Filter löschen
Filter löschen

convert labelmap to set of polygon lines

1 Ansicht (letzte 30 Tage)
em
em am 10 Feb. 2015
Kommentiert: Image Analyst am 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 Kommentar
em
em am 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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 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 Kommentar
Image Analyst
Image Analyst am 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);

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by