Reading Image Data

To display or manipulate image data in IDL, you must first create an IDL variable containing the image data. If your data is contained in a standard image format file (GIF, JPEG, etc.), you can use one of IDL's image file reading routines. If your data is contained in a non-standard format, you can use IDL's more generic binary data-reading mechanisms to import the data.

Reading Image Format Files

If your data is in a standard file format, use one of IDL's standard image reading routines. (See Image Reading Routines for a list.)

For example, to read in a JPEG file, use the READ_JPEG procedure. The following lines read a TrueColor JPEG image from the file rose.jpg in IDL's examples/data subdirectory into an IDL variable named rose:

file = FILEPATH('rose.jpg', SUBDIRECTORY=['examples', 'data'])
READ_JPEG, file, rose

(We will look at how to display the image data in the variable rose in Displaying TrueColor Images.)

Similarly, to read in a PNG file, use the READ_PNG function. The following lines read a greyscale PNG image from the file mineral.png in IDL's examples/data subdirectory into an IDL variable named mineral:

file = FILEPATH('mineral.png', SUBDIRECTORY=['examples', 'data'])
mineral = READ_PNG(file)

(We will look at how to display the image data in the variable mineral in Displaying Indexed Color Images.)

Note that some of IDL's image reading routines are procedures while others are functions. Consult the documentation for the routine that corresponds to your image file for details. As an alternative, you can use the READ_IMAGE function to read in an image file of unspecified type:

file = FILEPATH('mineral.png', SUBDIRECTORY=['examples', 'data'])
mineral = READ_IMAGE(file)

The READ_IMAGE routine will work with most standard image types, but does not provide as much control over how the image variable is created as do the format-specific routines.

Reading Binary Image Data

If your image data is in a nonstandard format, you can use the READ_BINARY routine to read binary information from the file. For example the following lines read byte data out of the file nyny.dat in IDL's examples/data subdirectory into an IDL variable named nyny:

file = FILEPATH('nyny.dat', SUBDIRECTORY = ['examples', 'data'])
imageSize = [768, 512]
nyny = READ_BINARY(file, DATA_DIMS = imageSize)

Here, we specify the size of the image array to be read via the DATA_DIMS keyword, and use the READ_BINARY routine's default data type (byte data).

(We will look at how to display the image data in the variable nyny in Displaying Indexed Color Images.)

Reading generic binary data into IDL variables is beyond the scope of this tutorial. Successfully reading such data requires that you know the data type and size of the array to be read. For additional information on reading binary data, see Files and Input/Output.

Further Information

For additional information on reading image data into IDL, see

Image Reading Routines

READ_BMP

Reads Microsoft Windows bitmap file (.BMP).

READ_DICOM

Reads an image from a DICOM file.

READ_GIF

Reads GIF file (.GIF)

READ_IMAGE

Reads the image contents of a file and returns the image in an IDL variable.

READ_INTERFILE

Reads Interfile (v3.3) file.

READ_JPEG

Reads JPEG file.

READ_JPEG2000

Reads JPEG 2000 file.

READ_MRSID

Reads MrSID file.

READ_PICT

Reads Macintosh PICT (version 2) bitmap file.

READ_PNG

Reads Portable Network Graphics (PNG) file.

READ_PPM

Reads PGM (gray scale) or PPM (portable pixmap for color) file.

READ_SRF

Reads Sun Raster Format file.

READ_TIFF

Reads TIFF format file.

READ_X11_BITMAP

Reads X11 bitmap file.

READ_XWD

Reads X Windows Dump file.