Displaying Images in 24-Bit Color

QUESTION: I have a 24-bit image. Most of the time when I display the image, it looks fine. But occasionally the colors look terrible. What is going on?

ANSWER: To display a 24-bit image on a Windows machine (this does not apply to UNIX machines, which apparently do the right thing) in its proper colors (as of IDL 5.2, when this article was written) one of two things has to be true: (1) The gray-scale color table is loaded (LoadCT, 0), or (2) color decomposition is turned on (Device, Decomposed=1).

The real key is the state of color decomposition. (In color decomposition a color value, say the 24-bit image pixel value, is decomposed into the red, green, and blue values that create a particular color on the display.) If color decomposition is turned off, the color or pixel value is used as an index into the color table to find the color value, rather than using the color value directly. In this state, the pixel value will correspond to the color value only when the gray-scale color table is loaded.

In practice, this means that before any 24-bit image is displayed, color decomposition should be turned on.

   Device, Decomposed=1
   TV, image24, True=1

Unfortunately, this isn't the whole story, because the Decomposed keyword is not an allowed keyword for many IDL graphics devices. For example, it is not appropriate for the Z-Graphics Buffer or for the PostScript devices. If you want to write code that can display an image on any graphics device (and what is the point of writing code that can't do this?), then what you actually have to write is something like this:

   CASE StrUpCase(!D.Name) OF
      'WIN': Device, Decomposed=1
      'MAC': Device, Decomposed=1
       'X' : Device, Decomposed=1
      ELSE:
   ENDCASE
   TV, image24, True=1

Now that's a lot of code to write for each TV command!

This is why I prefer to use my TVImage program to display images. Not only is TVImage device independent, but when displaying 24-bit images it always sets the Decomposed keyword on those devices that support it.

Google
 
Web Coyote's Guide to IDL Programming