Question

I'm trying to convert a grayscale image to rgb image . I searched the net and found this code:

rgbImage = repmat(grayImage,[1 1 3]);
rgbImage = cat(3,grayImage,grayImage,grayImage);

but what this does is only give the image in gray-scale with 3-D matrix. I want to have a way that i can convert it into true color image.

Was it helpful?

Solution

It's impossible to directly recover a colour image from the grey scale version of it. As correctly said by @Luis Mendo in the comments, the needed information are not physically stored there.

What you can do is try to come up with a mapping between intensity level and colour, then play around with interpolation. This however will not produce a good result, but just some colour mapping information that may be very far from what you want.

If you have another colour image and you want to fit its colours to your grey scale image, you may want to have a look at: http://blogs.mathworks.com/pick/2012/11/25/converting-images-from-grayscale-to-color/ .
In particular the function that is there cited can be found here: http://www.mathworks.com/matlabcentral/fileexchange/8214-gray-image-to-color-image-conversion#comments.

Bare in mind that this will be slow and will not produce a great result, however I don't think you can do much more.

OTHER TIPS

yes it's impossible to directly convert gray scale image to rgb..but it is possible to add features or show something like an edge detected on gray scale image in rgb by adding it..if you want you can use this..

rgb = zeros([size(I_temp) 3]);

rgb(:,:,1) = im2double(rr);

rgb(:,:,2) = im2double(rg)+.05*double(I_temp) ;

rgb(:,:,3) = im2double(rb);

where rr,rg,rb are an rgb base image..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top