필터 지우기
필터 지우기

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