Creating Image Objects
To create an image object, supply an array of pixel values to the IDLgrImage::Init method. If the image has more than one channel, be sure to set the INTERLEAVE property of the image object to the appropriate value. (See RGB Image Interleaving (Using IDL) for details and an example showing how to determine the interleaving within an image array.) See "IDLgrImage" (IDL Reference Guide) for details on object properties and methods.
Note
IDLgrImage does not treat NaN data as missing. If the image data includes NaNs, it is recommended that the BYTSCL function be used to appropriately handle those values. For example: oImage->SetProperty, DATA = BYTSCL(myData, /NaN, MIN=0, MAX=255)
In Object Graphics, binary, grayscale, indexed, and RGB images are contained in image objects. For display, the image object is contained within an object hierarchy, which includes a model object and a view object. The view object is then drawn to a window object. Some types of images must be scaled with the BYTSCL function prior to display.
For more information, refer to the following examples:
- Displaying Indexed Images with Object Graphics in the Examples section of "IDLgrPalette" (IDL Reference Guide).
Displaying Binary Images with Object Graphics
Binary images are composed of pixels having one of two values, usually zero or one. With most color tables, pixels having values of zero and one are displayed with almost the same color, such as with the default grayscale color table. Thus, a binary image is usually scaled to display the zeros as black and the ones as white.
The following example imports a binary image of the world from the continent_mask.dat binary file. In this image, the oceans are zeros (black) and the continents are ones (white). This type of image can be used to mask out (omit) data over the oceans. The image contains byte data values and is 360 pixels by 360 pixels.
Example Code
See displaybinaryimage_object.pro in the examples/doc/objects subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering displaybinaryimage at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT displaybinaryimage.pro.
- Determine the path to the
continent_mask.datfile: - Initialize the image size parameter:
- Use READ_BINARY to import the image from the file:
- Initialize the display objects:
- Initialize the image object:
- Add the image object to the model, which is added to the view, then display the view in the window:
- Initialize another window:
- Update the image object with a scaled version of the image:
- Display the view in the window:
- Clean up the object references. When working with objects always remember to clean up any object references with the OBJ_DESTROY routine. Since the view contains all the other objects, except for the window (which is destroyed by the user), you only need to use OBJ_DESTROY on the view object.
oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $
DIMENSIONS = imageSize, $
TITLE = 'A Binary Image, Not Scaled')
oView = OBJ_NEW('IDLgrView', $
VIEWPLANE_RECT = [0., 0., imageSize])
oModel = OBJ_NEW('IDLgrModel')
oModel -> Add, oImage oView -> Add, oModel oWindow -> Draw, oViewThe resulting window should be all black (blank). The binary image contains zeros and ones, which are almost the same color (black). A binary image should be scaled prior to displaying in order to show the ones as white.
oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $
DIMENSIONS = imageSize, $
TITLE = 'A Binary Image, Scaled')
Displaying Grayscale Images with Object Graphics
Since grayscale images are composed of pixels of varying intensities, they are best displayed with color tables that progress linearly from black to white. IDL provides several such pre-defined color tables, but the default grayscale color table is generally suitable.
The following example imports a grayscale image from the convec.dat binary file. This grayscale image shows the convection of the Earth's mantle. The image contains byte data values and is 248 pixels by 248 pixels. Since the data type is byte, this image does not need to be scaled before display. If the data was of any type other than byte and the data values were not within the range of 0 up to 255, the display would need to scale the image in order to show its intensities. Complete the following steps for a detailed description of the process.
Example Code
See displaygrayscaleimage_object.pro in the examples/doc/objects subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering displaygrayscaleimage at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT displaygrayscaleimage.pro.
- Determine the path to the
convec.datfile: - Initialize the image size parameter:
- Using READ_BINARY, import the image from the file:
- Initialize the display objects:
- Initialize the image object:
- Add the image object to the model, which is added to the view, then display the view in the window:
- Clean up the object references. When working with objects always remember to clean up any object references with the OBJ_DESTROY routine. Since the view contains all the other objects, except for the window (which is destroyed by the user), you only need to use OBJ_DESTROY on the view object.
oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $
DIMENSIONS = imageSize, $
TITLE = 'A Grayscale Image')
oView = OBJ_NEW('IDLgrView', $
VIEWPLANE_RECT = [0., 0., imageSize])
oModel = OBJ_NEW('IDLgrModel')
oModel -> Add, oImage oView -> Add, oModel oWindow -> Draw, oViewThe following figure shows the resulting grayscale image display.

