Previous Getting Started with IDL: Reading and Writing Data Next

Reading and Writing Images

You can import image data into IDL directly at the command line or also using the iImage tool.

Importing Image Data into an iTool

The iTools are fully interactive and automatically read your image data.

Here is an example of opening an image file in iImage:

  1. From the iImage window, select File  Open and from the examples\data directory choose a file named image.tif.
  2.  

  3. Select Open, and the file is displayed in iImage.

     

    Figure 3-1: Image.tif Displayed in iImage

    Figure 3-1: Image.tif Displayed in iImage

Importing Image Data at the Command Line

Reading image files directly into IDL is easy if you know the format in which the image is stored. First we must read in the image. Here we will use a TIFF format image of an aerial satellite view of Manhattan Island in New York City.

  1. Enter the following at the IDL Command Line to read the file into memory:
  2. MYIMAGE=READ_TIFF(FILEPATH('image.tif',SUBDIR= $
       ['examples', 'data']))  
    

     

  3. Now display the image:
  4. TV, MYIMAGE  
    

     

    Figure 3-2: Reading and displaying an image file

    Figure 3-2: Reading and displaying an image file

     


    Note
    Another way to import image data is to use the Import Image File toolbar button on the IDLDE toolbar. To use this feature simply click the button and the dialog will appear so that you may select "image.tif". However, this will name the image differently than shown in this example.

     

  5. Now, using IDL's WRITE_TIFF command, rename and write the file:
  6. WRITE_TIFF, 'imagecopy.tif', MYIMAGE  
    

  IDL Online Help (March 06, 2007)