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.

 채택된 답변

Walter Roberson
Walter Roberson 2013년 4월 29일

1 개 추천

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

댓글 수: 5

integra-t
integra-t 2013년 4월 30일
Removed the black and it work out perfectly. Thanks Walter!
Image Analyst
Image Analyst 2013년 4월 30일
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)
Image Analyst
Image Analyst 2013년 4월 30일
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 2013년 4월 30일
Thanks for the suggestions Image Analyst.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by