How to find specific areas in Voronoi plot? and how to enlarge the plot to choose small areas?
조회 수: 1 (최근 30일)
이전 댓글 표시
לק"י
Hi all, my name is Amit.
I'm trying to find the area of specific polygons in Voronoi's diagram which will be chosen by inpolygon command or other that can let me draw the area I wish to get.
for example:
the voronoi plot of the general chosen object is (disregard the drawn polygons):
As I mentioned, I want to get the area of polygons at a chosen circle or chosen polygon within this voronoi diagram.
the original code I tried (part of it from KSSV's previous answer - https://www.mathworks.com/matlabcentral/answers/446168-how-can-i-get-the-area-of-each-polygon-of-a-voronoi-diagram) was used just to take out a large object out of the scatter plot.
xnm=csvfilecontainingdots(:,1);
ynm=csvfilecontainingdots(:,2);
% scatterplot with filled circels (points) the CSV
scatter(xnm,ynm, 1, 'filled')
% save coordinates of a polygon. polygon will have j numbers of points.
[xpoly,ypoly]=ginput(10);
% hold plot
hold on
% take out the chosen polygon from the plot
% h = drawpolygon('FaceAlpha',0)
roi=inpolygon(xnm,ynm,xpoly,ypoly);
% mask out the ROI
xroi=xnm.*roi;
yroi= ynm.*roi;
% scatterplot the chosen area
hold off
figure (1)
scatter(xroi, yroi, 1, 'filled');
axis equal
% voronoi, used code from: https://www.mathworks.com/matlabcentral/answers/446168-how-can-i-get-the-area-of-each-polygon-of-a-voronoi-diagram
vor=voronoi(xroi, yroi);
[v,c] = voronoin([xroi yroi]) ;
% figure
% hold on
% voronoi(xroi,yroi)
vorareaacd45num10thin2nd = zeros(length(c),1) ;
for i = 1:length(c)
v1 = v(c{i},1) ;
v2 = v(c{i},2) ;
% patch(v1,v2,rand(1,3))
vorareaacd45num10thin2nd(i) = polyarea(v1,v2) ;
end
And one last thing.. when I try to use inpolygon, I can't enlarge the picture to get high detail of the desired area. do you have a solution for that?
Here you can see the magnification button is grey and unuseable:
Thank you!
Amit.
댓글 수: 0
채택된 답변
Matt J
2021년 8월 15일
You should use polyarea().
댓글 수: 2
Image Analyst
2021년 8월 15일
When you're computing the area of each polygon (which you said you already can do), then simply call inpolygon() to determine if all the vertices of that polygon are within the outline you hand drew. If it is within, keep that area, if it's not in, then discard that area.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Voronoi Diagram에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!