problem with boundary function

2 ビュー (過去 30 日間)
elnaz gh
elnaz gh 2022 年 7 月 15 日
編集済み: elnaz gh 2022 年 7 月 15 日
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 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by