Color Systems

Color can play a critical role in the display and perception of digital imagery. This section provides a basic overview of color systems, display devices, image types, and the interaction of these elements within IDL. The remainder of the chapter builds upon these fundamental concepts by describing how to load and modify color tables, convert between image types, utilize color tables to highlight features, and apply color annotations to images.

Color Schemes

Color can be encoded using a number of different schemes. Many of these schemes utilize a color triple to represent a location within a three-dimensional color space. Examples of these systems include RGB (red, green, and blue), HSV (hue, saturation, and value), HLS (hue, lightness, and saturation), and CMY (cyan, magenta, and yellow). Algorithms exist to convert colors from one system to another.

Computer display devices typically rely on the RGB color system. In IDL, the RGB color space is represented as a three-dimensional Cartesian coordinate system, with the axes corresponding to the red, green, and blue contributions, respectively. Each axis ranges in value from 0 (no contribution) to 255 (full contribution). By design, this range from 0 to 255 maps nicely to the full range of a byte data type.

An individual color is encoded as a coordinate within this RGB space. Thus, a color consists of three elements: a red value, a green value, and a blue value.

The following figure shows that each displayable color corresponds to a location within a three-dimensional color cube. The origin, (0, 0, 0), where each color coordinate is 0, is black. The point at (255, 255, 255) is white, representing an additive mixture of the full intensity of each of the three colors. Points along the main diagonal - where intensities of each of the three primary colors are equal - are shades of gray. The color yellow is represented by the coordinate (255, 255, 0), or a mixture of 100% red, plus 100% green, and no blue.

Figure 5-3: RGB Color Cube (Note: grays are on the main diagonal.)

imgcolor01.gif

Typically, digital display devices represent each component of an RGB color coordinate as an n-bit integer in the range of 0 to 2n –1. Each displayable color is an RGB coordinate triple of n-bit numbers yielding a palette containing 23n total colors. Therefore, for 8-bit colors, each color coordinate can range from 0 to 255, and the total palette contains 224 or 16,777,216 colors.

A display with an m-bit pixel can represent 2m colors simultaneously, given enough pixels. In the case of 8-bit colors, 24-bit pixels are required to represent all colors. The more common case is a display with 8 bits per pixel which allows the display of 28 = 256 colors selected from the much larger palette.

If there are not enough bits in a pixel to represent all colors, m < 23n, a color translation table is used to associate the value of a pixel with a color triple. This table is an array of color triples with an element for each possible pixel value. Given 8-bit pixels, a color table containing 28 = 256 elements is required. The color table element with an index of i specifies the color for pixels with a value of i.

To summarize, given a display with an n-bit color representation and an m-bit pixel, the color translation table, C, is a 2m long array of RGB triples:

Ci = {ri, gi, bi},   0 ≤ i < 2m

0 ≤ ri, gi, bi < 2n

Objects containing a value, or color index, of i are displayed with a color of Ci.

See "Color Table Manipulation" (IDL Quick Reference) for a list of color-related routines including those that covert RGB color triples to other color schemes.

Converting to Other Color Systems

IDL defaults to the RGB color system, but if you are more accustomed to other color systems, IDL is not restricted to working with only the RGB color system. You can also use either the HSV (hue, saturation, and value) system or the HLS (hue, lightness, and saturation) system. The HSV or HLS system can be specified by setting the appropriate keyword (for example /HSV or /HLS) when using IDL color routines.

IDL also contains routines to create color tables based on these color systems. The HSV routine creates a color table based on the Hue, Saturation, and Value (HSV) color system. The HLS routine creates a color table based on the Hue, Lightness, Saturation (HLS) color system. You can also convert values of a color from any of these systems to another with the COLOR_CONVERT routine. See COLOR_QUAN for more information.