Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

Using Macros to Import Image Files


To import an image file into IDL, complete the following steps:

  1. Select the Import Image File tool bar button. The Select Image File dialog is displayed.
  2. 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.
  3. 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.

  4. Click Open.
  5. 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.

Note
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:

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:

TV, MUSCLE_IMAGE.IMAGE 

This displays the following image:

If you want to know the file type, enter the following:

PRINT, MUSCLE_IMAGE.QUERY.TYPE 

IDL prints:

JPEG 

Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]