Returning Image File Information
When accessing formatted image data (not contained in a binary file), there are a number of ways to get information about the data characteristics. The most flexible is the QUERY_IMAGE routine, which returns a structure that includes the number of image channels, pixel data type and palette information. If you need specific information from a formatted image file, you can use the QUERY* routine specifically designed for images of that format.
Note
You can also use the SIZE function to quickly return the size of an image array. See Using SIZE to Return Image Dimensions for details.
Using the QUERY_IMAGE Info Structure
Common image file formats contain standardized header information that can be queried. IDL provides the QUERY_IMAGE function to return valuable information about images stored in supported image file formats.
For example, using the QUERY_IMAGE function, you can return information about the mineral.png file in the examples/data directory. First, access the file. Then use the QUERY_IMAGE function to return information about the file:
file = FILEPATH('mineral.png', $
SUBDIRECTORY = ['examples', 'data'])
queryStatus = QUERY_IMAGE(file, info)
To determine the success of the QUERY_IMAGE function, print the value of the query variable:
IDL prints
If queryStatus is zero, the file cannot be accessed with IDL. If queryStatus is one, the file can be accessed. Because the query was successful, the info variable is now an IDL structure containing image parameters. The tags associated with this structure variable are standard across image files. You can view the tags of this structure by setting the STRUCTURE keyword to the HELP command with the info variable as its argument:
IDL displays the following text in the Output Log:
** Structure <1407e70>, 7 tags, length=36, refs=1: CHANNELS LONG 1 DIMENSIONS LONG Array[2] HAS_PALETTE INT 1 IMAGE_INDEX LONG 0 NUM_IMAGES LONG 1 PIXEL_TYPE INT 1 TYPE STRING 'PNG'
The structure tags provide the following information:
|
Tag
|
Description
|
|---|---|
|
|
Provides the number of dimensions within the image array: Print the number of dimensions using:
For the |
|
|
Contains image array information including the width and height. Print the image dimensions using:
For the |
|
|
Describes the presence or absence of a color palette: Print whether a palette is present or not using:
For the |
|
|
Gives the zero-based index number of the current image. Print the index of the image using:
For the |
|
|
Provides the number of images in the file. Print the number of images in the file using:
For the |
|
|
Provides the IDL type code for the image pixel data type: See IDL Type Codes and Names under the SIZE function for a complete list of type codes. Print the data type of the pixels in the image using:
For the |
|
|
Identifies the image file format. Print the format of the file containing the image using:
For the |
From the contents of the info variable, it can be determined that the single image within the mineral.png file is an indexed image because it has only one channel (is a two-dimensional array) and it has a color palette. The image also has byte pixel data.
Note
When working with RBG images (with a CHANNELS value of 3) it is important to determine the interleaving (the arrangement of the red, green, and blue channels of data) in order to properly display these image. See RGB Image Interleaving (Using IDL) for an example that shows you how to determine the arrangement of these channels.
Using Specific QUERY_* Routines
All of the QUERY_* routines return a status, which determines if the file can be read using the corresponding READ_ routine. All of these routines also return the Info structure, (described in the previous section), which reports image dimensions, number of samples per pixel, pixel type, palette info, and the number of images in the file. However, some of the QUERY_* routines (such as QUERY_MRSID and QUERY_TIFF) return more detailed information particular to that specific image format. See "Query Routines" (IDL Quick Reference) for a complete list of the available QUERY_* routines.