convert gray image back to rgb
328 ビュー (過去 30 日間)
古いコメントを表示
how to back grat to rgb gray2rgb function not found
3 件のコメント
AliHdr
2021 年 10 月 30 日
I have done this but i can not use imwrite anymore
there is and error
<<Data with 9 components not supported for JPEG files.>>
how can I overwrite new rgb file with old gray file?
Image Analyst
2021 年 10 月 31 日
@AliHdr evidently JPG can't store multispectral or volumetric images. Either use a mat file or save each slice as its own image.
採用された回答
Image Analyst
2013 年 3 月 14 日
If you have a color map - a mapping of what intensity should go to what color, like what imread() or rgb2ind() can give you - then you can use ind2rgb.
rgbImage = ind2rgb(grayImage, colormap);
Otherwise use
rgbImage = cat(3, grayImage, grayImage, grayImage);
grayImage needs to be in the range 0-255 uint8 if you want to display it.
3 件のコメント
Alexandar
2022 年 7 月 1 日
What do you mean by create a colormap and how can you do it within the scales that you'd like?
Image Analyst
2022 年 7 月 1 日
@Alexandar There are a bunch of built-in colormap functions such as hsv, turbo, and jet. Or you can make up your own 256 by 3 matrix with values in the range 0-1.
その他の回答 (3 件)
Shaun VanWeelden
2013 年 3 月 14 日
Alternatively
rgb=img(:,:,[1 1 1]); does the same thing as Jan's, but is a little shorter maybe and easier to remember. img is your image you want to convert to rgb obviously
4 件のコメント
Image Analyst
2016 年 11 月 18 日
No, that throws an error if img is a gray scale image since there is no third dimension for gray scale images.
Jan
2013 年 3 月 14 日
Asking Google for "Matlab gray2rgb" would be a good idea.
But a general method is:
RGB = cat(3, Gray, Gray, Gray);
4 件のコメント
Walter Roberson
2022 年 7 月 2 日
sample_logical_2d = rand(64,80) > 0.8;
imshow(sample_logical_2d)
sample_logical_3d = cat(3, sample_logical_2d, sample_logical_2d, sample_logical_2d );
try
imshow(sample_logical_3d)
catch ME
fprintf('oooo! imshow did not like 3D logical!')
disp(ME)
end
sample_double_3d = double(sample_logical_3d);
imshow(sample_double_3d)
shehbaz Ali
2013 年 3 月 14 日
This is not possible to to convert black and white image to gray image. Because you don't what will be colors of any pixel for rgb picture.
5 件のコメント
Walter Roberson
2023 年 6 月 14 日
You cannot gain information when you convert black and white to grayscale, or grayscale to color -- but you can create the grayscale or color image with the same amount of information.
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!