Borrar filtros
Borrar filtros

convert labelmap to set of polygon lines

1 visualización (últimos 30 días)
em
em el 10 de Feb. de 2015
Comentada: Image Analyst el 11 de Feb. de 2015
I have a labelmap e.g.
A=[0 0 0 1
0 1 1 2
0 1 1 2
1 2 2 1]
I want to get a set of polygon lines that describes this labelmap. For example
label 0: (1,3),(1,1),(3,1),(1,3) %label 0 is the polygon region connecting these points
and so on. Is there any efficient way of doing so?
  1 comentario
em
em el 10 de Feb. de 2015
Just to make it more clear. I have a labelmap matrix describing an image. As shown in the image, it is visualized in Matlab by
imshow(im,[])
How can I extract polygon boundaries describing each label region? For all labels, I would have a set of polygon boundaries. What is the most efficient way of extract all these polygon boundaries?

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 10 de Feb. de 2015
You're talking about the convex hull, convhull(). It's sort of like this
A=[0 0 0 1
0 1 1 2
0 1 1 2
1 2 2 1]
[rows, columns] = find(A==0)
xy = [rows,columns]
indexes = convhull(xy)
r = rows(indexes)
c = columns(indexes)
but I don't have time now to do exactly what you want. convhull gives all points on the outer edges, like the 2,2 element, which you don't want for some reason. Maybe it'll be okay though if you just describe why you want the data in this form.
  1 comentario
Image Analyst
Image Analyst el 11 de Feb. de 2015
Regarding your clarification (wish you had posted that originally) -- you don't want what you originally asked for at all . You don't want lines. You want the boundary pixel locations. So simply use bwboundaries():
labelNumber = 3; % Whatever label you want
boundary = bwboundary(labeledImage == labelNumber);
x = boundary{1}(:, 2);
y = boundary{1}(:, 1);

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by