IPCOLOR_24_8 Function
Converts a 24-bit color image to an 8-bit color image; or, converts an 8-bit color image to a 24-bit color image.
Usage
result = IPCOLOR_24_8(image[, in_cmap])
Input Parameters
image—A 2D or 3D array containing an image; or image, row or pixel-interleaved images.
in_cmap—(Used for 8 to 24-bit conversion only.) A 3-by-n_colors array containing the colormap for image, where n_colors 256.
Returned Value
result—A 2D or 3D byte array containing the converted image.
*If image is 3D, it is assumed to contain a 24-bit color image; therefore, the conversion is from 24-bit color to 8-bit color, and result is an 8-bit color image (a 2D byte array of the same x and y-dimensions as image).
*If image is 2D, it is assumed to contain an 8-bit color image; therefore, the conversion is from 8-bit color to 24-bit color, and result is an 24-bit color image (a 3D byte array of the same x and y-dimensions as image).
Keywords
Valid For Both Types of Conversion:
Bmap—Specifies a variable to hold the blue colormap created for the converted image.
Gmap—Specifies a variable to hold the green colormap created for the converted image.
Intleave—(For 3D image: 24-bit to 8-bit conversion) A scalar string indicating the type of interleaving of the 3D input array.
(For 2D image: 8-bit to 24-bit conversion) A scalar string specifying the interleaving of the 24-bit result image. Valid strings and the corresponding interleaving methods are:
*'pixel'—The input array arrangement is (pxy) for p  pixel-interleaved images of x-by-y.
*'row'—The 3D image array arrangement is (xpy) for p  row-interleaved images of x-by-y.
*'image'—The 3D image array arrangement is (xyp) for p  image-interleaved images of x-by-y.
Noloadct—If set, the colormap created during conversion is not automatically loaded.
Rmap—Specifies a variable to hold the red colormap created for the converted image.
For 24 to 8-Bit Conversion Only:
N_Colors—The number of colors used in the 8-bit result image. (Default: !D.Table_Size)
One of the following keywords should be set; the MedCut keyword is the default, if none is selected.
Floyd—If set, Floyd-Steinberg dithering is used to quantize a 24-bit image to 8 bits.
MedCut—Is set, the median cut algorithm is used to quantize a 24-bit image to 8 bits. (Default: set)
Pctrans—If set, the principle components transform is used to quantize a 24-bit image to 8 bits.
For 8 to 24-Bit Conversion Only:
Linear—If set, specifies linear ramps from 0 to 255 for the red, green, and blue color tables; otherwise, the current PV‑WAVE color table is used. Valid only if the in_cmap parameter is not specified.
Discussion
Converting an image from 24-bit to 8-bit is called color quantization and is useful for displaying 24-bit images on 8-bit displays. It’s also convenient to compress the image information from three planes into a single plane to reduce the computation time needed for image processing operations.
 
note
Information is lost during the conversion from 24-bit to 8-bit, which means the conversion is not fully reversible.
Conversion from 8-bit to 24-bit is sometimes a useful trick for processing the image as three separate planes. It is also useful for loading a mixture of 8-bit and 24-bit images into the Image Tool on the Image Processing Navigator by converting the 8-bit images to 24-bit before starting the Image Tool.
Example 1: 8-Bit to 24-Bit Conversion
Converting an image from 8-bit to 24-bit is sometimes convenient as a “trick” for processing the image as separate layers. For example, you can conveniently apply three different threshold ranges to a 24-bit image as follows:
; Read in an 8-bit image.
image_8bit = IMAGE_READ(!IP_Data + 'photo.tif')
; Convert the 8-bit image to 24 bit.
image_24bit = IPCOLOR_24_8(image_8bit('pixels'), $
image_8bit('colormap'))
; Threshold each plane separately as follows:
;    Plane 1:  20 <= x <= 50
;    Plane 2:  30 <= x <= 45
;    Plane 3:  25 <= x <= 100.
thresh_planes = THRESHOLD(image_24bit, $
[20, 30, 25], [50, 45, 100], Intleave = 'image')
WINDOW, 0
TVSCL, thresh_planes(*, *, 0)
WINDOW, 1
TVSCL, thresh_planes(*, *, 1)
WINDOW, 2
; Now, display each plane separately.
TVSCL, thresh_planes(*, *, 2)
Example 2: 24-Bit to 8-Bit Conversion
; Convert the image to 8 bit for display, using the median cut
; algorithm and Floyd-Steinberg dithering.
image_24bit = IMAGE_READ(!IP_Data + 'boulder_image.tif')
image_8bit = IPCOLOR_24_8(image_24bit('pixels'), $
/Floyd, Rmap = r, Gmap = g, Bmap = b)
; Set the device to 8-bit pseudocolor.
TVLCT, r, g, b
TV, image_8bit
See Also
In the PV‑WAVE Reference:  IMAGE_COLOR_QUANT