Using Macros to Import Image Files
To import an image file into IDL, complete the following steps:
- Select the Import Image File tool bar button. The Select Image File dialog is displayed.
- Select a file to import. For example, select the
rsi-directory
/examples/data/muscle.jpg
file where
rsi-directory
is the installation directory for IDL.
You can now see a preview of this image as well as other information about the file in the lower section of the Select Image File dialog. You can change the preview to Color, Grayscale, or No Preview. If the image file had more than one actual image, you can see them using the arrow buttons to scroll through the images. You can only read in one image of a multi-image file. The image in the preview is the image that will be read.
- Click Open.
- The file has been opened into a structure variable named MUSCLE_IMAGE.
Images opened with the Import Image File macro are stored in structure variables which are named filename_IMAGE where filename is the name of the file you opened without the extension.
IDL variables must begin with a letter, and may contain only letters, digits, the underscore character, or the dollar sign. If the first character of filename is not a letter, the prefix "var" is added to the variable name. Any spaces within filename are converted to underscores. Any other illegal characters within filename are removed.
So, the file we just opened (muscle.jpg) is now in the structure variable named MUSCLE_IMAGE. The file is a structure with the following fields:
- IMAGE - The actual image array.
- R - The red color table vectors.
- G - The green color table vectors.
- B - The blue color table vectors.
- QUERY - Contains information about the image.
- CHANNELS - The number of channels in the image.
- HAS_PALETTE - Specifies if the palette is present. 1 if the palette is present, else 0. If your image is n-by-m the palette is usually present and the R, G, and B color table vectors mentioned above will contain values. If your image is 3-by-n-by-m, the palette will not be present and the R,G, and B color table vectors will not contain any values.
- IMAGE_INDEX - The index of the image of the file. The default is 0, the first image in the file. If there are multiple images in the file that you read, this will be the number (or index) of the image.
- NUM_IMAGES - The number of images in the original file.
- PIXEL_TYPE - The IDL Type Code of the image pixel format. Valid types are:
PIXEL_TYPE returned
|
Data Types
|
1
|
Byte
|
2
|
Integer
|
3
|
Longword Integer
|
4
|
Floating Point
|
5
|
Double-precision Floating Point
|
12
|
Unsigned Integer
|
13
|
Unsigned Longword Integer
|
14
|
64-bit Integer
|
15
|
Unsigned 64-bit Integer
|
- TYPE - The image type. Valid return values are:
BMP, JPEG, PNG, PPM, SRF, TIFF, DICOM
The structure can be viewed in the Variable Watch Window.
You can specify which part of the structure variable you want to access by using the following syntax:
variable_name.element_name[.element_name]
For example, if you want to view the image, enter the following:
This displays the following image:
If you want to know the file type, enter the following:
IDL prints: