MATLAB: Grayscaled Images to RGB

gray to colorgray2rgbimageprocessingMATLAB

I am working over gray scaled images that would want to specify a single color for there, is there a way to specify which color to convert it to… for example i have a gray scale image that would like to have it go between 0 to 255 RED… is there a way to do that???

Best Answer

If your image array is IM and it is already the datatype that you want, then
red_IM = cast(cat(3, IM, zeros(size(IM)), zeros(size(IM))), class(IM));
green_IM = cast(cat(3, zeros(size(IM)), IM, zeros(size(IM))), class(IM));
blue_IM = cast(cat(3, zeros(size(IM)), zeros(size(IM)), IM), class(IM));
If your grayscale is 0 to 1 and you want to convert it to 0 to 255, then before doing the above, do
IM = uint8(IM * 256);