convert labelmap to set of polygon lines

4 views (last 30 days)
em
em on 10 Feb 2015
Commented: Image Analyst on 11 Feb 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 Comment
em
em on 10 Feb 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?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 10 Feb 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 Comment
Image Analyst
Image Analyst on 11 Feb 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);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!