How to change gray scale to rgb
14 ビュー (過去 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 で Orange についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!