How to get a color image with labeling from a binary image?
11 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Image Analyst
2019-9-19
% 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
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
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 Center 和 File Exchange 中查找有关 Red 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!