How to get a color image with labeling from a binary image?

조회 수: 17 (최근 30일)
SUKUMAR NAGINENI
SUKUMAR NAGINENI 2019년 9월 19일
댓글: Image Analyst 2019년 9월 21일
Dear sir,
We have a dilated image (binary image), we need to convert it into a color image with the labelling. Anyone can help me to get this color image with labelling? if you a have any idea, please let me know about it.
Dailated color image output labeling
Thanks

답변 (1개)

Image Analyst
Image Analyst 2019년 9월 19일
Here is a snippet from my Image Segmentation Tutorial:
% Identify individual blobs by seeing which pixels are connected to each other.
% Each group of connected pixels will be given a label, a number, to identify it and distinguish it from the other blobs.
% Do connected components labeling with either bwlabel() or bwconncomp().
labeledImage = bwlabel(binaryImage, 8); % Label each blob so we can make measurements of it
% labeledImage is an integer-valued image where all pixels in the blobs have values of 1, or 2, or 3, or ... etc.
subplot(3, 3, 4);
imshow(labeledImage, []); % Show the gray scale image.
title('Labeled Image, from bwlabel()', 'FontSize', captionFontSize);
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
% coloredLabels is an RGB image. We could have applied a colormap instead (but only with R2014b and later)
subplot(3, 3, 5);
imshow(coloredLabels);
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
caption = sprintf('Pseudo colored labels, from label2rgb().\nBlobs are numbered from top to bottom, then from left to right.');
title(caption, 'FontSize', captionFontSize);
Adapt as needed.
  댓글 수: 2
Arijit Chattopadhyay
Arijit Chattopadhyay 2019년 9월 20일
Dear Sir,
In Simulink,in matlab function block when we use this code,it shows an error as: "In code generation, LABEL2RGB does not support colormap functions for MAP".
Image Analyst
Image Analyst 2019년 9월 21일
It works in MATLAB. I don't have Simulink so it it works differently there, then I don't know - you'll just have to look at the documentation as to how to specify a colormap for the different/unique blobs.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by