필터 지우기
필터 지우기

bwboundaries - label each object with different color

조회 수: 3 (최근 30일)
Ely Raz
Ely Raz 2013년 10월 14일
답변: Image Analyst 2013년 10월 14일
Hi,
In this example below the labeled objects are shown using the jet colormap, on a gray background, with region boundaries outlined in red.
Therefore, how can I change the background to white and label each object with different color?
%based on http://www.mathworks.es/es/help/images/ref/bwboundaries.html
I = imread('rice.png');
BW = im2bw(I, graythresh(I));
[B,L] = bwboundaries(BW,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 2)
end
Cheers and thanks.

채택된 답변

Image Analyst
Image Analyst 2013년 10월 14일
Yes, a list of standard colors is given here: http://en.wikipedia.org/wiki/List_of_colors Hover over the color to find the rgb values. Then replace 'r' in your code with the color you want. Or you can use a row from a built-in colormap, such as myColorMap(k, :).
myColorMap = jet(length(B));
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'Color', myColorMap(k,:), 'LineWidth', 2)
end

추가 답변 (1개)

Anand
Anand 2013년 10월 14일
The third input to label2rgb is the specification for zero-color, i.e. the background.
You can specify a black background by replacing the call to imshow with the call below:
imshow(label2rgb(L, @jet, [0 0 0]))
  댓글 수: 2
Ely Raz
Ely Raz 2013년 10월 14일
Thanks. Is there a link describing the color codes (e.g., [0 0 0]=black)?

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by