How to convert grayscale image to rgb with full colors? [closed]

二次信任 提交于 2019-12-13 09:22:45

问题


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.


回答1:


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.




回答2:


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..



来源:https://stackoverflow.com/questions/21833683/how-to-convert-grayscale-image-to-rgb-with-full-colors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!