Previous Using IDL: Getting Information About Files and Data Next

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:

PRINT, 'Status = ', queryStatus  

IDL prints

queryStatus =           1  

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:

HELP, info, /STRUCTURE  

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:

 

Table 2-1: Image Structure Tag Information 

Table 2-1: Image Structure Tag Information 
Tag
Description
CHANNELS
Provides the number of dimensions within the image array:
  • 1 – two-dimensional array
  •  

  • 3 – three-dimensional array
Print the number of dimensions using:
PRINT, 'Number of Channels: ', info.channels  
For the mineral.png file, IDL prints:
Number of Channels:           1  
DIMENSIONS
Contains image array information including the width and height. Print the image dimensions using:
PRINT, 'Size: ', info.dimensions  
For the mineral.png file, IDL prints:
Size:           288         216  
HAS_PALETTE
Describes the presence or absence of a color palette:
  • 1 (True) – the image has an associated palette
  •  

  • 0 (False) – the image does not have an associated palette
Print whether a palette is present or not using:
PRINT, 'Is Palette Available?: ', info.has_palette  
For the mineral.png file, IDL prints:
Is Palette Available?:           1  
IMAGE_INDEX
Gives the zero-based index number of the current image. Print the index of the image using:
PRINT, 'Image Index: ', info.image_index  
For the mineral.png file, IDL prints:
Image Index:           0  
NUM_IMAGES
Provides the number of images in the file. Print the number of images in the file using:
PRINT, 'Number of Images: ', info.num_images  
For the mineral.png file, IDL prints:
Number of Images:           1  
PIXEL_TYPE
Provides the IDL type code for the image pixel data type:
  • 0 – Undefined
  •  

  • 1 – Byte
  •  

  • 2 – Integer
  •  

  • 3 – Longword integer
  •  

  • 4 – Floating point
  •  

  • 5 – Double-precision floating
  •  

  • 6 – Complex floating
  •  

  • 9 – Double-precision complex
  •  

  • 12 – Unsigned Integer
  •  

  • 13 – Unsigned Longword Integer
  •  

  • 14 – 64-bit Integer
  •  

  • 15 – Unsigned 64-bit Integer
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:
PRINT, 'Data Type: ', info.pixel_type  
For the mineral.png file, IDL displays the following text in the Output Log:
Data Type:           1  
TYPE
Identifies the image file format. Print the format of the file containing the image using:
PRINT, 'File Type: ' + info.type  
For the mineral.png file, IDL prints:
File Type: PNG  

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 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 for a complete list of the available QUERY_* routines.

  IDL Online Help (March 06, 2007)