How would I color objects red?

I know I can use the command label2rgb to color the objects with specified color maps but how would I go about making all objects red in an image?
Thank you in advance for any help that is provided.

 Risposta accettata

relabeled = uint8(labeled_image > 0);
colormap = [0 0 0; 1 0 0]; %black and red
coloredimage = label2rgb(relabeled, colormap);

5 Commenti

integra-t
integra-t il 30 Apr 2013
Removed the black and it work out perfectly. Thanks Walter!
The black is the background (non-objects). How can you remove that? If the objects are red, and now your background is also red, because you made it red instead of black, then the whole image is red.
Here is my code with Walter's input included at the very end minus the black portion of it.
A1=imread('smear.jpg');
imshow(A1);
A2=A1(:,:,1)-0.4*(A1(:,:,3)) - 0.6*(A1(:,:,2));
figure, imshow(A2);
A3= A2> 19;
A4= bwareaopen(A3, 200);
figure, imshow(A4);
A5=bwconncomp(A4);
[A6]=bwlabel(A4);
colormap = [1 0 0];
A7=uint8(A6>0);
A8=label2rgb(A7,colormap);
imshow(A8)
That's a pretty poor segmentation. You didn't really need colormapping at all, you need a good color segmentation algorithm. By looking at your 3D color gamut I can tell that you'd classify the grayish purple objects much better by doing this
  1. convert to hsv with rgb2hsv()
  2. extract H, S, and V channels separately.
  3. the objects you want can be thresholded by taking V less than something, and S between one value and another.
I have examples in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862. Try the HSV one with your image and play around with the thresholds. You'll get a much better segmentation.
integra-t
integra-t il 30 Apr 2013
Thanks for the suggestions Image Analyst.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by