PV-WAVE Foundation > User Guide > Displaying Images > Using Color with Images
Using Color with Images
Color is a valuable aid in the visual analysis process, because it can be used to distinguish fine gradations of shade and intensity. For this reason, color plays a very important role when viewing images.
For color and gray-scale devices, the default is to display 8-bit images using the color table B–W Linear (standard color table number 0).
 
note
On a monochrome display color images are dithered. For more information about dithering, see "Images on 24-bit Devices (UNIX)".
Color Systems
Most devices capable of displaying color use the RGB (red, green, blue) color system. By default, PV‑WAVE represents images in the RGB color system using triplets of values for the red, green, and blue components of a particular pixel’s color.
For more information about how image data is stored and transferred, refer to "Input and Output of Image Data" of the PV‑WAVE Programmer’s Guide.
If you are interested in seeing a more complete discussion of color systems, refer to "Understanding Color Systems" on page 283.
Using Color Tables to View Images
PV‑WAVE provides two commands for viewing images: TV and TVSCL. These two commands were introduced earlier in section "Image Display Routines: TV and TVSCL".
By default, images are displayed using color table number 0, B–W Linear. To use a color table other than the default, load it prior to displaying the image, as shown in the following example:
; Load the predefined color table number 5, Standard Gamma-II.
LOADCT, 5
TV, image   ; You could also use: TVSCL, image
includes an assortment of 16 predefined color tables with enough variety to produce visually pleasing results for many applications, or you can define your own color table. To see a list of the color tables that come standard with PV‑WAVE, refer to "Loading a Predefined Color Table: LOADCT" on page 289.
Loading a Different Color Table
Most color workstations cannot display more than a certain number of colors (usually 256) at once. For this reason, color tables are used to map red, green, and blue values into the available colors on the workstation.
You can use either the TVLCT or the LOADCT procedures to load the color table on the current device:
*LOADCT—This procedure loads predefined color tables stored in the file colors.tbl. These tables are located in:
(UNIX) <wavedir>/bin
(WIN) <wavedir>\bin
Where <wavedir> is the main PV-WAVE directory.
*TVLCT—This procedure loads color tables stored in user-defined variables. Once the variables are loaded into the color table, it is used like any other color table.
For more information about loading the various color tables, see "Experimenting with Different Color Tables" on page 288. For more information about creating custom color tables that emphasize some special trend or effect, see "Modifying the Color Tables" on page 291.
Color Tables for Viewing Images
Be sure to experiment with the sixteen color tables that are included with . Frequently, a trend that is “hidden” when viewing an image with one color table stands out with clarity when viewing the image with another color table.
The color tables that work best for viewing images are the ones that do not have sudden transitions from one color table index to the next. Otherwise, you will probably see a strong banding or “contouring” effect that is created by the rapid transitions between colors.
For an example of how to de-emphasize and moderate the color transitions in a color table, refer to "Smoothing the Color Transitions in a Color Table" on page 294.
Not all Color Images True-color Images (UNIX)
This section on true-color images does not pertain to the Windows version of PV‑WAVE.
Images may be output with 1, 2, 3, 4 or 8 bits per pixel, yielding 1, 2, 16, or 256 possible colors. In addition, color images are either: 1) pseudo-color or 2) true-color. These two approaches to storing image information are contrasted in the following sections.
 
note
Not all output devices allow you to control the number of bits used to represent each pixel. To see if your device supports this capability, refer to the PV‑WAVE Reference.
Pseudo-color Images
A pseudo-color image is a two-dimensional image, each pixel of which is used to index the color table, thereby obtaining an RGB value for each possible pixel value. An 8-bit workstation monitor usually displays pseudo-color images.
In the case of pseudo-color images of less than 8 bits, the number of columns in the image should be an exact multiple of the number of pixels per byte. In other words, when displaying a 2-bit image the number of columns should be even, and 4-bit images should have a number of columns that is a multiple of 4. If the image column size is not an exact multiple, extra pixels with a value of 255 are output at the end of each row. This causes no problems if the color white is loaded into the last color table entry, otherwise a stripe of the last (index number 255) color is drawn to the right of the image.
True-color Images
A true-color image consists of an array with three dimensions, one of which has a size of three, containing the three color components. It may be considered as three two-dimensional images, one each for the red, green, and blue components. For example a true-color n-by-m element image can be ordered in three ways: pixel interleaved (3, n, m), row interleaved (n, 3, m), or image interleaved (n, m, 3). By convention the first color is always red, the second green, and the last is blue.
True-color images are routed through the color table, just like pseudo-color images. The red color table array contains the intensity translation table for the red image, and so forth. Assuming that the color table has been loaded with the vectors R, G, and B, a pixel with a color value of (r, g, b) is displayed with a color of (Rr, Gg, Bb). A color table value of 255 represents maximum intensity, while 0 indicates an absence of the color.
To pass the RGB pixel values without change, load the red, green, and blue color tables with a ramp with a slope of 1.0:
TVLCT, INDGEN(256), INDGEN(256), INDGEN(256)
or with the LOADCT procedure:
; Load the standard black/white color table, B–W Linear.
LOADCT, 0
Use the True keyword of the TV and TVSCL procedures to indicate that the image is a true-color image and to specify the dimension over which color is interleaved. Allowed values are:
*1—pixel interleaving
*2—row interleaving
*3—image interleaving
 
note
Image interleaving is also known as band interleaving.
To see specific examples showing how to use the True keyword, see the examples in the section "Images on 24-bit Devices (UNIX)".
For more information about the different ways that image data may be stored, refer to "Input and Output of Image Data" of the PV‑WAVE Programmer’s Guide.
Images on Monochrome Devices (UNIX)
This section on monochrome devices does not pertain to the Windows version of PV‑WAVE.
Images are automatically dithered when sent to some monochrome devices. Dithering is a technique which increases the number of apparent brightness levels at the expense of spatial resolution. Images with 256 gray levels are displayed on a display with only two brightnesses, black and white, using halftoning techniques.
PV‑WAVE supports dithering for output devices if their DEVICE procedures accept the keywords described below:
*Floyd—If present and nonzero, selects the Floyd-Steinberg method of dithering. This algorithm distributes the error, caused by displaying intermediate shades in either black or white, to surrounding pixels. This method generally gives the most pleasing results but requires the most computation time.
*Ordered—If present and nonzero, selects the Ordered Dither method of dithering. This introduces a pseudo-random error into the display by using a 4-by-4 “dither” matrix, yielding 16 apparent intensities. The Ordered Dither method is enabled by default.
*Threshold—If present and nonzero, specifies use of the threshold algorithm—the simplest dithering method. The value of this keyword is the threshold to be used. This algorithm simply compares each pixel against the given threshold, usually 128. If the pixel equals or exceeds the threshold, the display pixel is set to white; otherwise, it is black.
 
note
PostScript handles dithering directly, and does not recognize the keywords listed above.
Images on 24-bit Devices (UNIX)
This section on 24-bit devices does not pertain to the Windows version of PV‑WAVE.
You can use PV‑WAVE to display images in 24-bit color. Naturally, your workstation must support 24-bit color mode if you intend to view 24-bit images with PV‑WAVE. Similarly, hardcopy devices must support 24-bit color mode if you intend to send 24-bit color output to them. To find out if your device has this capability, see the PV‑WAVE Reference.
 
note
24-bit images may be either square or rectangular; they can be either pixel, row, or image interleaved. There is no restriction placed on the size of images by PV‑WAVE; the limiting factors are the maximum amount of virtual memory available to you by the operating system and the processing time required.
Refer to the examples later in this section for more information about how to read and display 24-bit images with PV‑WAVE. For a comparison of true-color and pseudo-color images, refer to "Not all Color Images True-color Images (UNIX)".
Example: Read and Display a 24-bit Image-interleaved Image
This example reads 24-bit image data from a file, and then displays the image in a window using 24-bit color. The 24-bit image is stored in a file as a set of stacked images, 512-by-512-by-3 deep (first the 512-by-512 red plane, then the 512-by-512 green plane, and then the 512-by-512 blue plane). The display device is an X-compatible device, and is capable of displaying 24-bit color:
; Define a DirectColor graphics window.
DEVICE, Direct_Color=24
; Read the 24-bit image from a file; DC_READ_24_BIT 
; handles opening and closing of the file. The variable ‘img’ now
; contains a 512-by-512-by-3 image array. Org=1 tells
; DC_READ_24_BIT that the file is image interleaved (as opposed
; to pixel interleaved).
status = DC_READ_24_BIT(’jl.img’, img, Org=1)
; Display the 24-bit image using either the TV or the TVSCL
; procedures. The True keyword specifies the dimension over which
; the color is interleaved.
TV, img, True = 3   ; You could also use: TVSCL, img, True = 3
Example: Read and Display a 24-bit Image Stored in Three Different Files
This example reads 24-bit image data that has been stored in three separate image files—one red, one green, and one blue. Each file is read separately and then combined in one 3D array prior to displaying the 24-bit image. The data used in the example comes from the red, green, and blue images of Boulder in the $WAVE_DIR/data area.
DEVICE, Direct_Color=24
; Define three 477-by-512 variables to hold the image data. 
; Each variable holds one “plane” of the data.
red = MAKE_ARRAY(477, 512, /Byte)
green = red
blue = red
; Read each plane (red, green, and blue) of the image, placing the
; data in three different variables.
OPENR, 1, GETENV(’WAVE_DATA’) + ’/boulder_red.img’
READU, 1, red
CLOSE, 1
OPENR, 1, GETENV(’WAVE_DATA’) + ’/boulder_grn.img’
READU, 1, green
CLOSE, 1
OPENR, 1, GETENV(’WAVE_DATA’) + ’/boulder_blu.img’
READU, 1, blue
CLOSE, 1
; Create a 3D 24-bit image array and transfer each plane of the
; image into it.
img = MAKE_ARRAY(477, 512, 3, /Byte)
img(*, *, 0) = red
img(*, *, 1) = green
img(*, *, 2) = blue
; Display the 24-bit image using either the TV or the TVSCL 
; procedures. The True keyword specifies the dimension over which
; the color is interleaved.
TV, img, True = 3   ; You could also use: TVSCL, img, True = 3
 
note
This example could have also used DC_READ_8_BIT to read the image data, and then the data files would not have had to be explicitly opened and closed. For more information about this function, see the DC_READ_8_BIT description in the PV‑WAVE Reference.