How can i fill in the vectors gotten from boundary function?
Mostra commenti meno recenti
Hello. I have coordinates of 2D points and found the closed boundary of the clouds. And I need a binarized 2D array which is filled inside the boundary.
How can I use the vector(k) returned from boundary function (boundary(x,y))?
for example,
x = gallery('uniformdata',30,1,1);
y = gallery('uniformdata',30,1,10);
k = boundary(x,y);

I have tried to save the plotted image and to use "find" function. But it was not a good idea because there were missing pixels (not colored pixels) at the edge. Thus, I am finding the way to use the vector (k) directly.
Thanks for all.
Risposta accettata
Più risposte (1)
Steven Lord
il 17 Ott 2018
Generate sample data and compute the boundary.
rng default
x = gallery('uniformdata',30,1,1);
y = gallery('uniformdata',30,1,10);
k = boundary(x,y);
Use the coordinates and the boundary information to create a polyshape.
P = polyshape(x(k), y(k));
Make a grid that spans the rectangle that covers the polyshape.
[minx, maxx] = bounds(x);
[miny, maxy] = bounds(y);
queryx = linspace(minx, maxx, 20);
queryy = linspace(miny, maxy, 20);
[xm, ym] = meshgrid(queryx, queryy);
xm = xm(:);
ym = ym(:);
Determine which points are inside the polyshape.
isin = isinterior(P, xm, ym);
Plot the polyshape and the points. Points in the grid that are inside the polyshape are green circles, points that are outside the polyshape are red X markers.
plot(P, 'FaceColor', 'w');
hold on;
plot(xm(isin), ym(isin), 'go')
plot(xm(~isin), ym(~isin), 'rx')
3 Commenti
Image Analyst
il 17 Ott 2018

HyunSang Park
il 18 Ott 2018
Image Analyst
il 18 Ott 2018
I added that release to the question (at the upper right, like you should have done when you originally posted). So now, what about my answer above, though poly2mask requires the Image Processing toolbox, but patch doesn't)?
Categorie
Scopri di più su Polygonal Shapes in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!