How to change gray scale to rgb

1 次查看(过去 30 天)
TURI
TURI 2012-11-1
Hi everyone.
I have image
I=[ 0.6429 0.6429 0.6468 0.6468 0.6429 0.6429 0.6429 0.6429 0.6429
0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429
]
Now i want to change all values 0.6429 to red color.
  1 个评论
Walter Roberson
Walter Roberson 2012-11-2
Just that one specific value should be changed to red and the rest should remain gray, or are you trying to convert all the grayscale values back to their original RGB values?

请先登录,再进行评论。

回答(2 个)

Image Analyst
Image Analyst 2012-11-1
Not so easy, for a few reasons. One is that it's floating point and you need to be cognizant of the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F. Secondly, color floating point images are a bit tricky to display. They won't display unless they're in the 0-1 range, which luckily yours happen to be. But it they were some arbitrary floating point values, you'd need to either convert to 0-1 and leave as floating point, or scale to 0-255 and cast to uint8. Third, you said "Change all values" so I take this to mean you want to change the values (actually below I make a copy rather than change in place) but it's possible to change them only upon display and leave the original values intact. You can do that with colormap() but since it seems like you want to change the variable rather than just make it appear differently, I did that with the code below.
I=[ 0.6429 0.6429 0.6468 0.6468 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 0.6429 ];
subplot(1,2,1);
imshow(I, []);
valueToReplace = 0.6429;
lowValue = valueToReplace - eps(100);
highValue = valueToReplace + eps(100);
% Find values close to 0.6429 floating point.
locationsOf6429 = (I >= lowValue) & (I <= highValue)
redChannel = I;
greenChannel = I;
blueChannel = I;
% Make locationsOf6429 1 in the red channel
redChannel(locationsOf6429) = 1.0;
% Make locationsOf6429 black in the green and blue channel
greenChannel(locationsOf6429) = 0;
blueChannel(locationsOf6429) = 0;
% Make an RGB image for display
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
subplot(1,2, 2);
% Display it. Works only if all values are between 0 and 1
% otherwise scale to 0-255 and cast to uint8.
imshow(rgbImage);

TURI
TURI 2012-11-1
Thanks for your reply, Actually the above image 'I' was rgb image then i convert it to gray, its matrix is 480x640. I just copy the matrix that i need to convert back to rgb. Now in gray image all the pixel values that is equal 0.0429 was red in rgb image before. I am not sure that you understand me or not?
  1 个评论
Image Analyst
Image Analyst 2012-11-1
编辑:Image Analyst 2012-11-1
No, if what I gave you didn't do the job, then I don't. Did you use rgb2hsv() and then need to use hsv2rgb() now? Or you just want to use a colormap (a pseudocolor look up table)? By the way, this should have been a comment since you did not submit an "Answer" to your own question.

请先登录,再进行评论。

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by