How to find specific areas in Voronoi plot? and how to enlarge the plot to choose small areas?
4 次查看(过去 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):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/712417/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/712422/image.png)
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!