How do I convert multiple discontinuous lines into a single polyshape?
6 次查看(过去 30 天)
显示 更早的评论
For the image attached, I have the coordinates of the points along each individual line, with these lines having been extracted from a contour map. The blue lines show the low amplitude boundaries, while the yellow lines indicate the direction of increasing amplitude. From these line coordinates I am hoping to create polyshapes.

The issue I'm having is that because some of the lines are discontinuous, going beyond the axes limits, when I fill them in they only fill the region bound by that line, not considering the other lines around them. As such, I was wondering if there was an easy way to have Matlab automatically join up the lines that should contribute to the same region (i.e. the 2 seen in the top left or the 3 at the bottom of the figure below) so that I can get polyshapes of the regions I'm interested in?

Thank you in advance for any help you can offer!
3 个评论
Matt J
2022-10-14
it isn't entirely necessary to make them into polyshapes, although I was wanting to do this so that I can easily track their centroids.
regionprops(im>0.41,'Centroid')
采纳的回答
Matt J
2022-10-14
编辑:Matt J
2022-10-14
Using this FEX download,
load im.mat
imp=padarray(im,[1,1]);
[m,n]=size(im);
levels=[0.4,0.41];
clear p
for i=1:numel(levels)
M=contourc(imp,[levels(i),levels(i)]);
[~,XY]=getContourLineCoordinates(M);
X=cellfun(@(z) z(:,1)-1, XY,'uni',0);
Y=cellfun(@(z) z(:,2)-1, XY,'uni',0);
p(i)=polyshape(X,Y);
end
plot(p);axis equal;
set(gca,'YDir','reverse');
axis([1,m,1,n]);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Elementary Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
