MATLAB: What is the difference between RGB Image and Colormap

image processingImage Processing Toolbox

What is the difference between RGB Image and Colormap? Why we need to use [X,map] = imread('trees.tif') in colormap when compared to I = imread('board.tif'); J = rgb2gray(I); in RGB?

Best Answer

In an RGB image, each pixel is individually supplied with the information about what its Red, Green, and Blue components are. The image can be painted directly.
In a pseudocolor image, each pixel is a single value which is a color number. The color numbers have no independent meaning: color #8 might be completely different than #7 or #9. The color numbers are references to a table of colors that say what the R, G, B components are for each color number. So two pixels that both have color #8 will be looked up in the same table location, and pixels with color #7 would be looked up in an adjacent table location, but the RGB values for the adjacent entries can be completely different.
pseudocolor is a "Paint By Number" set.
You can make a pseudocolor image look quite different visually by changing the colormap without changing the color numbers.
Color numbers do not themselves have any gray-level information; color numbers are just arbitrary. "I'll take whatever color is behind door #3, Bob." RGB images, on the other hand, directly have all the information needed in order to calculate brightness (gray) level.
Related Question