IPLINEAR_GRAY Function
Transforms an image with a nonlinear grayscale or pseudocolor colormap to a linear grayscale image.
Usage
result = IPLINEAR_GRAY(image, in_cmap)
Input Parameters
image—A 2D array containing an image.
in_cmapA 3-by-n_colors array containing the colormap for image, where n_colors 256.
Returned Value
result—A 2D byte array containing the image transformed to a linear grayscale colormap.
Keywords
Colormap—Specifies a variable to receive the output linear grayscale colormap.
The following three keywords control the IPLINEAR_GRAY function behavior for image values falling outside the colormap range. The Clip keyword is the default if none is specified.
Clip—If set, clips values outside the colormap range to the range {0, ..., to n_colors – 1}. (Default)
Scale—If set, scales values lying outside the colormap range into the range {0, ..., n_colors – 1}.
Wrap—If set, uses the MOD operator to wrap values lying outside the colormap range into the range {0, ..., n_colors – 1}.
Discussion
The Scale, Clip, and Wrap  keywords are particularly useful when image is not a byte array, because they specify how values outside the colormap range are translated into the colormap.
The transformation process for IPLINEAR_GRAY works differently for grayscale than for pseudocolor input images. If the input colormap is already a grayscale colormap, the input colormap is used as a translation table to form the output image from the input image. If the input colormap is not a grayscale colormap, it is first transformed to the HSV (Hue Saturation Value) color model. The value component, which represents brightness, is then used as the translation table to form the output image from the input image.
Example
This example illustrates how to convert an 8-bit pseudocolor image to linear grayscale. First, read an image using the appropriate path name for your operating system as shown.
; Read an image.
(UNIX) image = IMAGE_READ(!Data_Dir + '../..' + $
'/image-1_0/data/multi_dogs.gif')
(WIN) image = IMAGE_READ(!Data_Dir + '..\..' + $
'\image-1_0\data\multi_dogs.gif')
; Transform the image to grayscale.
gray_image = IPLINEAR_GRAY(image('pixels'), $
image('colormap'), /Clip, Colormap = cmap)
; Load the new colormap.
TVLCT, REFORM(cmap(0,*)), REFORM(cmap(1,*)), REFORM(cmap(2,*))
; Display the image.
TV, gray_image
See Also