problem with boundary function
4 次查看(过去 30 天)
显示 更早的评论
Hello everybody
I want to find the 2D points (Namely "A" matrix attached; first row is X coordinate and second row is Y) which are included in the boundary that is around some other 2D data (namely "OnPixel" matrix attached here ); I used "boundary" built in matlab function to find the boundary around "OnPixel" , then used "inpolygon" to find which points in "A" are in the found boundary (boundary around "OnPixel" ). But unfortunately the "boundary" function DOES NOT extract the boundary correctly (some how find the convexhull but not the exact boundary)!!!
Therefore the points in "A" that are detected as the ones inner the "OnPixel" boundary are much more than the exact answers; In fact the points out of the correct boundary ARE detected wrongly;
i.e. From the attached picture: I want to find black boundary but blue boundary is detected; (red are Points in "OnPixel" )
Note: May be XY information of points in "A" are not EXACTLY written as XY of one of the points in "OnPixel"; BUT may be spreaded through the points and in it's boundary. (I mean we can not use "ismember" to find the points)
Can you please help me to find the correct boundary and consequently correct points of "A" in the boundary around "OnPixel"?
I really appriciate any help
Code:
figure;hold on; plot(OnPixel(:,2),OnPixel(:,1),'.','color','r')
boundN=boundary(OnPixel(:,2),OnPixel(:,1));
bound=OnPixel(boundN,1:2);
hold on;plot(bound(:,2),bound(:,1),'k')
ObjectPloygon=polyshape(bound(:,2),bound(:,1));
[in,on]=inpolygon(A(1,:),A(2,:),ObjectPloygon.Vertices(:,1),ObjectPloygon.Vertices(:,2));
inn_Obj=[find(in),find(on)];
innX=A(1,inn_Obj);
innY=A(2,inn_Obj);
hold on;plot(innX,innY,'.','color','cyan')
0 个评论
回答(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!