How to get mask from boundary()
16 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
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
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')
More Answers (0)
See Also
Categories
Find more on Bounding Regions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!