How to calculate Area of overlapping polygons inside square

8 ビュー (過去 30 日間)
cvk engineer
cvk engineer 2020 年 5 月 16 日
コメント済み: darova 2020 年 5 月 18 日
I have requirement to calculate percentage of area covered by polygons inside square(Green Border) for matlab plot.
Logic used is Area coverage= Area of outer square- area of each polygon- polygon overlapping area
I am stuck at finding overlapping area as there are more than 3 polygons overlapping. I am using intersect function for finding intersection
Is there any better method for this requirement(Can Non-plotted are be measured?)

採用された回答

Steven Lord
Steven Lord 2020 年 5 月 16 日
Take the union of all the polyshape objects representing your polygons
Make a polyshape representing the interior and boundary of your square and intersect that square with the union polyshape.
This results in one final polyshape whose area you can compute.
  3 件のコメント
Steven Lord
Steven Lord 2020 年 5 月 17 日
The polyshape representing a square and its interior is easy. Here's the unit square.
square = polyshape([0 1 1 0 0], [0 0 1 1 0]);
plot(square)
I'm assuming you want the intersection of the triangles inside the square, not just a measurement of how much of the green line representing the outside of the square covers the triangles. Making that square "annulus" would be a little trickier; there's probably a way to do this using polybuffer but a quick way to do it would be:
figure
square = polyshape([0 1 1 0 0], [0 0 1 1 0]);
w = 0.05;
inner = polyshape([w 1-w 1-w w w], [w w 1-w 1-w w]);
plot(subtract(square, inner))
Change w and recreate the inner polyshape to change how thick or thin the "ring" is.
cvk engineer
cvk engineer 2020 年 5 月 18 日
Issue solved, Thank you so much.
I took union of all the polygons, created polygon of coverage square, got area of intersection of these two..

サインインしてコメントする。

その他の回答 (1 件)

darova
darova 2020 年 5 月 17 日
編集済み: darova 2020 年 5 月 17 日
What about this simple trick?
I = imread('image.png');
I1 = imcrop(I, [70 75 130 95]);
I2 = im2bw(I1,0.95);
imshowpair(I1,I2,'montage')
sum(~I2(:))
You need only to scale pixels to area
  2 件のコメント
cvk engineer
cvk engineer 2020 年 5 月 18 日
imcrop needs image processing toolbox which i dont have, thanks.
darova
darova 2020 年 5 月 18 日
Just select region you want
I = imread('image.png');
I1 = im2bw(I1,0.95);
I2 = I1(70:200,75:170);
imshowpair(I1,I2,'montage')
sum(~I2(:))

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by