MATLAB: How to convert gray image to rgb image after filtering

image processingImage Processing Toolbox

RGB = imread('peppers.png');
imshow(RGB)
I = rgb2gray(RGB);
figure
imshow(I)

Best Answer

I know my answer might sound like beating around the bush which makes no sense but I think this is what you are asking. I assume you want to know about different color channels if so this is the answer.
% Get back original color RGB image
RGB = imread('peppers.png');
figure, imshow(RGB,[])
channel1 = RGB(:,:,1);
channel2 = RGB(:,:,2);
channel3 = RGB(:,:,3);
grayImg = rgb2gray(RGB);
figure, imshow(grayImg)
actualImg = cat(3,channel1,channel2,channel3);
figure, imshow(actualImg)
But in reality, If u don't have the RGB saved for later use, You cannot retrieve the exact original color image from the converted grayscale image
what i meant to say is:
grayImg = rgb2gray(RGB);
figure, imshow(grayImg)
if this is the only current information available for you and no access to RGB, you cannot get back actual color image
Let me know if this is what you are trying.
Gopi