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:
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
- READ_BINARY in the IDL Reference Guide
- Files and Input/Output in Application Programming
- Documentation for individual image file reading routines (listed below) in the IDL Reference Guide
Image Reading Routines