How to change gray scale to rgb
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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
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);
댓글 수: 0
TURI
2012년 11월 1일
댓글 수: 1
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 Center 및 File Exchange에서 Red에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!