Matlab – Combine three grayscale images into RGB with MATLAB

imageMATLAB

I have three grayscale images where each image represents a single channel from a RGB image of 16-bit resolution. I would like to convert them to obtain one single RGB image. I have tried cat and ind2rgb but it is not working. Should we index our grayscale images before using ind2rgb? Is there any other way of doing it?

Thanks

Best Answer

Assuming you have three matrices R,G,B of type int16. If you try

RGB = cat(3,R,G,B);
imshow(RGB)

IMSHOW will complain that: RGB images must be uint8, uint16, single, or double.. In fact if you check the documentation:

A truecolor image can be uint8, uint16, single, or double. An indexed image can be logical, uint8, single, or double. A grayscale image can be logical, uint8, int16, uint16, single, or double. A binary image must be of class logical.

So if you concatenate three int16 grayscale images, and you want to use IMSHOW, you have to convert the resulting truecolor image to something it supports:

imshow( im2double(RGB) )
Related Topic