convert labelmap to set of polygon lines

조회 수: 4 (최근 30일)
em
em 2015년 2월 10일
댓글: Image Analyst 2015년 2월 11일
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);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by