Basic IDL operations with images

The purpose of this exercise is to become familiar with opening, displaying and analyzing image files using tools provided by IDL.

Preparation

If you have not done so, create a directory named "images" in your account to hold images that you will work with. Then use your browser or an ftp tool to obtain images from the directory http://www.cis.rit.edu/class/simg782/images. Store a selection of images in your images directory. You should store the images with their file extensions (*.png, *.jpeg, *.tif, etc.)

Construct a directory named "idlhw" to hold your IDL homework programs. Add this directory to the IDL path. This can be done with the file->preferences dialog box. Use the path tab.

Open the IDL development environment. If you are using a Unix X-Windows system, type "idlde &" at the command prompt. If you are using another platform, start IDL as described for that system.

Step 1

Open a new IDL editor page.

Enter the following lines into the page:

fname=dialog_pickfile(FILTER='*.png')
image=READ_IMAGE(fname)
imSize=SIZE(image)
WINDOW,/FREE,XSIZE=imSize[1],YSIZE=imSize[2],TITLE=fname
TVSCL,image

Save the page as prog1.pro in the idlhw directory that you created.

Step 2

Type the command @prog1 in the IDL command window. This will run the program in the file prog1.pro. If IDL can't find the file, you have to update your path reference. The first command in the file will cause a dialog box to appear on your screen. Use this dialog box to navigate to your images directory and then select one of the images. The FILTER parameter causes only png files to be shown. After you select the image and click OK, the system should display an image.

Step 3

Look up each of the procedures and functions that are used in the program. Each line contains one procedure or function. Both keyword and positional parameters are used. You should be able to explain the use of each parameter and the result of each command. You can find out more about each of the variables fname, image and imSize by typing HELP,fname, for example, at the IDL command line. Also type PRINT,fname and PRINT,imSize at the command line.

Step 4

Investigate the image. The image is just an array of numbers. We can extract a row or column from the image and plot it. For example, type the following commands into the command line.

WINDOW,1
y=imSize[2]/2
profile=image[*,y]
PLOT,profile

You should see a window with a plot of the image brightness along a horizontal slice halfway up the image. Determine what each of the above commands does. Use a similar technique to plot the image profile across other horizontal and vertical slices. See if you can determine the location of points such as edges of objects.

What is happening in the command profile=image[*,y]? How would you select another row (or column) to plot?

Look up the PLOT procedure in IDL help and find out how to add titles and gridlines to your plots by using keyword parameters.

Look up the information on OPLOT. Use it to make plots at several horizontal slices on the same graph.

Step 5

This is an exercise in array indexing and image display.

1. Extract the upper right quadrant of image and put it into a new array called subImage.

2. Construct a new window of the right size for the quadrant and display the subImage.

Step 6 Saving graphics

You often want to save things that are shown in a graphics window, such as an image or a graph. If you look around in IDLDE for a menu command to save graphics you won't find it. To save the contents of a graphics window we do the following:

WSET,1 ;Select the window whose contents you want. Here it is window 1.
A=TVRD() ;Put the contents of the window into an array using TVRD()
fwrite=DIALOG_PICKFILE() ;Construct the full path with filename.
WRITE_PNG,fwrite,A ;Write the array to the file. This file will have the png format.

There are a lot of variations on this basic theme. Look up each of the commands to see how they can be modified by keyword parameters. There are other commands like WRITE_TIFF, WRITE_JPEG, for other file formats. See IDL Help for more information.