Conversion of grayscale image into RGB and CIELAB color space

4 次查看(过去 30 天)
HI everyone,
please guide me if anyone know. I have Grayscale images (0-255) and i want to convert that grayscale images into RGB images (3 channels) and CILab color space images. please help me in coding.
ref grayscale image is attach.

回答(2 个)

Rik
Rik 2021-12-10
To convert a grayscale image to RGB you need a colormap.
G=imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/795434/vidf6_33_002_f010.png');
map=colormap; %select the active colormap, probably not what you want
%convert to RGB
RGB=ind2rgb(G,map);imshow(RGB)
As for the conversion to CIELab, you should read this answer by Image Analyst.

DGM
DGM 2023-5-18
编辑:DGM 2023-5-18
I would think that the obvious choice would be
% an I/RGB image
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/795434/vidf6_33_002_f010.png');
% expand it to RGB
if size(inpict,3) == 1
rgbpict = repmat(inpict,[1 1 3]);
else
rgbpict = inpict;
end
% convert to LAB
labpict = rgb2lab(rgbpict);
... of course if your images are all grayscale, what's the advantage of converting them to LAB? Unless you're trying to feed grayscale images into a process that handles things in LAB, you're generating a bunch of useless extra data. There is no information in the chroma channels, so the only thing of value is L*. If all you need is L*, you can just do.
% convert to L*
lpict = rgb2lightness(rgbpict);

类别

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