convert labelmap to set of polygon lines

1 次查看(过去 30 天)
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 个评论
em
em 2015-2-10
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?

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2015-2-10
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 个评论
Image Analyst
Image Analyst 2015-2-11
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);

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by