How can I color only specific blobs in my segmented image?

1 view (last 30 days)
I have a segmented/labeled image. There are some segments that are too big, and I have their blob indices. I would like to color those blobs red while keeping the other blobs white. How can I do that? My current code below keeps the badBlobs, but turns the other blobs black.
Also, I would like the badBlobs to all be red, not with a spectrum like in the hsv colormap. How can I do that?
I am attaching the image that I am using.
And this is the result that I'm getting:
I want all other blobs to be visible as well, but in white.
Thanks.
Edit: wording
badBlobs = [25];
newImage = segmentedImage;
%Keep only blobs that are too big
binaryImage = ismember(newImage, badBlobs);
labeledImage = bwlabel(binaryImage);
%Show bad openings
figure('Name', 'Bad openings', 'numbertitle', 'off');
imshow(labeledImage);
colormap('hsv')

Accepted Answer

Image Analyst
Image Analyst on 16 Feb 2022
colorizedImage = imoverlay(segmentedImage, binaryImage, 'r');
  1 Comment
Andrea Labudzki
Andrea Labudzki on 16 Feb 2022
Hi Image Analyst! Thanks for the answer. This worked perfectly! Over the past few months, you've helped me so much with my project. This is my final thesis for my Engineering Bachelors and you've helped me countless times so thank you so so much!! I really appreciate all your answers. :D

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!