In labelled binary image, fill the blobs with different colors defined by me.

1 次查看(过去 30 天)
Hello,
I have this labelled binary image with multiple blobs. I want to fill the labelled blobs with colors defined by me. For example: as shown in image, blobs of label 2,4 and 8, I want them to be filled with green color. Similarly, blobs of label 5,6 and 11, I want them to be filled with red color. Rest blobs should be filled with blue color. I know about label2rgb command but dont know how to do this color filling with label2rgb.
How to do this?

采纳的回答

darova
darova 2020-5-25
  • use bwselect to select specific blob. Assign pixels value: red - 1, green - 2, blue - 3
  • create your own colormap and use it to display colors
I1 = bwselect(I,coord_red); % choose pixels in red group
I2 = bwselect(I,coord_green); % choose pixels in green group
I3 = bwselect(I,coord_blue); % choose pixels in blue group
II = I1*1 + I2*2 + I3*3; % create new image
% create new colormap
cmap = [0 0 0 % black
1 0 0 % red
0 1 0 % green
0 0 1]; % blue
ishow(II,cmap) % display new image with new colors
  2 个评论
Naseeb Gill
Naseeb Gill 2020-5-26
编辑:Naseeb Gill 2020-5-26
Thanks for your response. But I don't know how to choose the specific blob? For example I want to select blob 5,6 and 11. How to select this using bwselect? It will be helpful if you show me code to choose the specific blob and then color it.
darova
darova 2020-5-26
Try this simple examlpe
I0 = imread('im1.png');
I1 = im2bw(I0);
cmap = jet(5); % experiment with colormap
II = 0*double(I1);
subplot(211)
imshow(I1)
for i = 2:5
p = ginput(1); % pick point
I2 = bwselect(I1,p(1),p(2)); % select region
II = II + I2*i; % paint region in
subplot(212)
imshow(II,cmap)
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by