MATLAB: Colormap function not able to change colormap of an image

colormapImage Processing Toolbox

I have been trying to use colormap to simply change the colors of an image that I am working with. I have seen many examples online of simply just saying
colormap(jet) or colormap(hsv)
and this works for the example images.
However, when I try to do this with my image it doesn't work. I assume that the reason it doesn't work is because my image is already a colored image.
Everytime that I try the colormap(map) function it just reproduces the same image that I originally uploaded.
If someone could tell me why it's not working if I'm not correct and what I can do to actually change the colormap of the image I would greatly appreciate it.
Thanks, HBI

Best Answer

Correct - a colormap does not apply for a true color RGB image. RGB images don't have colormaps, which are essentially lookup tables to convert a gray level into a color. To change the color of a pixel in an RGB image you just do it directly by changing the R, G, and B values. There is no single "index" or gray level like there is with an indexed image. If you want to convert your RGB image into an indexed image, you can do so with the rgb2gray() function. Or you can do color segmentation (like in my File Exchange http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 ) to identify some region of the image that matches some criteria you specify, and then create a binary image to change whole regions into the desired color.