how to convert a grayscale image to rgb image

Answers (3)

cat(3, YourImage, YourImage, YourImage)
The result will be a truecolor image that happens to only use gray tones.

2 Comments

amir
amir on 22 Aug 2012
Moved: DGM on 29 Dec 2023
Dear Walter could you please clarify the process? i didn't get how to execute the commend? many thanks
For example:
YourImage = rgb2gray( imread('lena.tif') );
newImage = cat(3, YourImage, YourImage, YourImage);

Sign in to comment.

This should also work:
rgbImage = ind2rgb(grayImage, gray(256));
though I usually use the cat() method given by Walter.

1 Comment

The cat() method will work when the grayscale image is class single or double, or uint8 or uint16, but ind2rgb() requires uint8 or uint16.

Sign in to comment.

Asked:

on 18 Apr 2012

Answered:

DGM
on 29 Dec 2023

Community Treasure Hunt

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

Start Hunting!