convert gray image back to rgb

조회 수: 609 (최근 30일)
zzz
zzz 2013년 3월 14일
댓글: DGM 2023년 6월 15일
how to back grat to rgb gray2rgb function not found
  댓글 수: 3
AliHdr
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
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
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
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
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.
To apply the colormap to the data range you want, you can use the clim or caxis() function.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Shaun VanWeelden
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
SHAIKH TAUSEEF HASAN
SHAIKH TAUSEEF HASAN 2016년 11월 18일
rgb=img(:,:,[1 2 3]);
Image Analyst
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
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
john
john 2022년 1월 10일
what do u mean by use double? its giving me error when i use imshow
Walter Roberson
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
oooo! imshow did not like 3D logical!
MException with properties: identifier: 'images:imageDisplayValidateParams:expected2D' message: 'If input is logical (binary), it must be two-dimensional.' cause: {} stack: [7×1 struct] Correction: []
sample_double_3d = double(sample_logical_3d);
imshow(sample_double_3d)

댓글을 달려면 로그인하십시오.


shehbaz Ali
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
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.
DGM
DGM 2023년 6월 15일
That's a good way to put it. :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by