How to get mask from boundary()

16 次查看(过去 30 天)
Hi,
I have points that represents curve levels. With thoses, I can find the boundary (k) matrix:
x = [1 2 3 4 3 2];
y = [4 5 5 4 3 3];
k = boundary(x,y);
I would like to make a mask from this boundary, but the function "boundary" does not provide the same output that "bwboundaries" does. Therefore, I cannot make a mask.
So, how can I make a mask with this data?

采纳的回答

KSSV
KSSV 2019-2-20
x = [1 2 3 4 3 2]';
y = [4 5 5 4 3 3]';
k = boundary(x,y);
plot(x,y,'.r')
hold on
patch(x(k),y(k),'k')
  7 个评论
KSSV
KSSV 2019-2-21
x = [1 2 3 4 3 2]';
y = [4 5 5 4 3 3]';
k = boundary(x,y);
x0 = min(x) ; x1 = max(x) ;
y0 = min(y) ; y1 = max(y) ;
[X,Y] = meshgrid(linspace(x0,x1),linspace(y0,y1)) ;
idx = inpolygon(X(:),Y(:),x(k),y(k)) ;
% X(~idx) = NaN ;
% Y(~idx) = NaN ;
plot(x,y,'.r')
hold on
patch(x(k),y(k),'k') ;
plot(X(idx),Y(idx),'.r')
plot(X(~idx),Y(~idx),'.b')
Hugo Daniel
Hugo Daniel 2019-2-21
Wow, I could not think of a better result! Thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Bounding Regions 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by