How to get mask from boundary()

16 views (last 30 days)
Hugo Daniel
Hugo Daniel on 20 Feb 2019
Commented: Hugo Daniel on 21 Feb 2019
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?

Accepted Answer

KSSV
KSSV on 20 Feb 2019
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 Comments
KSSV
KSSV on 21 Feb 2019
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 on 21 Feb 2019
Wow, I could not think of a better result! Thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Bounding Regions in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!