1

I obtain the index map and colormap using [index_map,colormap] = imread('indexed_color_image.tif'); And then I show the result using two different commands. Their results look very different.

Case 1: figure;imshow(uint8(index_map), colormap);

case 2: figure; imshow(double(index_map), colormap);

Could you give some explanation ? Thanks ! This is the original image.(indexed image).

enter image description here

The result of case 1 is as the original image. But the result for case 2 is weired. See this

enter image description here

tqjustc
  • 3,624
  • 6
  • 27
  • 42
  • Hint: what is a colormap for? – nispio Oct 20 '13 at 07:41
  • I have explained it in the question body. When we imread an indexed color image, we will have two results: index_map and colormap. This is the basic definition of indexed color images – tqjustc Oct 20 '13 at 07:48
  • I was asking for your sake, not mine... A colormap is a mapping between pixel values and colors, if you map two different values with the same colormap, you should expect two different colors to be displayed. So what are the differences between the values in `uint8(index_map)` vs. `double(index_map)`? Have you compared them? – nispio Oct 20 '13 at 08:02
  • @tqjustc it would help if you could add the two figures to your question. – Shai Oct 20 '13 at 08:17
  • @nispio See the question body. I added the result. It is weired. So I asked this question. – tqjustc Oct 20 '13 at 08:49
  • 1
    @Shai I have added the figure. My system is Ubuntu 13.04 64-bit. thanks – tqjustc Oct 20 '13 at 08:49

1 Answers1

3

It took a couple of hours of digging through the docs, but I finally figured out what the difference is. This comes from the documentation for the image function, which is eventually called after a call to imshow:

Double-Precision Data (double Array):

Image is stored as a two-dimensional (m-by-n) array of integers in the range [1, length(colormap)]; colormap is an m-by-3 array of floating-point values in the range [0, 1].

8-Bit Data (uint8 Array) 16-Bit Data (uint16 Array):

Image is stored as a two-dimensional (m-by-n) array of integers in the range [0, 255] (uint8) or [0, 65535] (uint16); colormap is an m-by-3 array of floating-point values in the range [0, 1].

So the answer is that the uint8 data is expected to be in the range [0, 255], while the double data is expected to be in the range [1, 256]. I was able to confirm this by trying this:

[imdata, immap] = imread('ostrich.png');
imhandle = imshow(1+double(imdata),immap);

Matlab infers from the datatype how it should index the colormap. It happens to be different for uint8 vs. double, and that is why you saw the strange behavior.

nispio
  • 1,743
  • 11
  • 22
  • 2
    Also, apologies for being so quick to assume that your question was just a misunderstanding of what a colormap does. It turned out to be much more subtle than that! :) – nispio Oct 20 '13 at 10:39