Professional Documents
Culture Documents
IDL Lab 1 - The IDL Interface
IDL Lab 1 - The IDL Interface
IDL Lab 1 - The IDL Interface
Name:
Introduce the student to the initial concepts and use of IDL and ENVI to:
import, analyze, and output image data
learn to interface between ENVI input/outputs and IDL code
The questions provided within this lab are designed to help the student better understand the
practical details of programming in IDL and are recommended but are not for assessment.
Login: XXXX
Password: XXXX
1
Before you start:
This starts both ENVI (The Environment for Visualizing Images) and the IDL (Integrated
Development Language) programming interface
Ignore the ENVI toolbar but dont close it as this closes IDL as well.
The menu and toolbars are explanatory but we will typically only be making use of the
File and Run menu bars.
Programs are written within the editor box
When a program is run, all the subroutines that are called or errors identified are
displayed in the log area
The command line allows direct commands to be typed into IDL without the need of a
written program
Editor Box
Objects
and
Groups
Log Area
Command Line
2
Task #1: Importing a file in IDL and outputting a modified file to be read by ENVI
Each program in IDL must be called from the saved files. This is done by starting each
program with the command PRO followed by its program name. All programs must be finished
with the command END.
To work in IDL this program needs to be saved as the identical word typed after PRO: i.e. in this
case intro. This is done using FILE/SAVE AS from the menu bar.
To create the archetypical Hello World! program we need to use the PRINT to screen
command.
The SYNTAX NOTES below shows you how the command and text should be written within
IDL.
SYNTAX NOTES like this will be used throughout this and future labs as a source of future
reference.
Once you have written the text you would like to print within the program you first need to save
the changes to the program by pressing the SAVE icon in the menu bar.
3
Press CTRL+F5 (OR RUN/COMPILE from the menu bar) to compile the program.
If the program is successful, then the output should be presented in the LOG area:
After each program is compiled and run it is necessary to clear the computers temporary
memory. This is achieved by typing retall into the command line and pressing enter.
To end a program that has hung the system, use RUN/stop followed by RUN/Resolve
dependencies from the menu bar.
Well done, you have just completed your first IDL program!
4
Step 3 Entering Image Data into IDL for Analysis
To open an image file in IDL that can be read or modified you need to use the OPEN command,
of which there are three variations in IDL:
Namely,
Each separate file must have a unique unit number so that is can be distinguished. The file
path includes the directory.
We want to make our Hello World! program more impressive by taking in an image file and
creating a modifed copy that ENVI can display.
In the editor box type the following lines (the comments are optional):
;; 400 (columns). Placing FLT before ARR tells IDL that the file contains real (floating point)
;; numbers. You would type INTARR for an array of integers and BYTARR for an array of
;; bytes. There are many many more ARR types that can be found in the IDL help file.
READU, 1, A ;; This line tells IDL to place the image into the array A
CLOSE, 1 ;; This line tells IDL that we are finished reading the file.
You will use these 4 lines of code again and again when programing in IDL.
5
We now want to create an exact copy of the image, add 100 to each value and then write the
result to a new file so that it can be read by ENVI. To do this we are going to create two other
arrays called B and C:
6
This is our complete IDL program. We now want to save, compile and run the program
following the instructions in Step 2.
If any errors occur check that all the commas are where they should be; the file name; and that
the original file is in the correct directory.
We are no going to turn away from IDL and use ENVI for the second half of this Lab.
7
Task #2: Importing the modified IDL file into ENVI
Minimize the IDL work area and select the ENVI toolbar:
To input the modified file we just created in IDL we select FILE/Open Image File and then
select the file name (not the .hdr file) from the open file window:
This file currently does not have a header file (.hdr). These files contain information on the size
and type of numbers contained within the file. Each time a new file such as this is entered into
ENVI you need to manually tell ENVI this information by using the following box that appears
once you press open in the box above.
8
The file we outputted in IDL had 400
rows (lines) and 400 columns (samples).
Pressing OK brings up the Available Bands List, which tells you what files are currently open
in ENVI. If you double click on Band1 of ouput1 you will get to view the IDL file you created:
9
To open the original unaltered file, you can also use the Available Bands List.
Press File/Open Image File and select the file image1. The file image1 will appear in the
Available Bands List box.
To display this image alongside the modified file you first need to create a new display to view it
in. This is done by clicking on the button Display #1 and selected New Display.
You will see that the Display #1 button now says Display #2 and that a blank image box has
appeared. If you now double click on band 1 of image 1 this should display image 1 in this
display box:
Zoom
Window
As you can see these images look identical so how do we know if we actually did anything with
the IDL program.
To assess pixel values within an image double left click on the main image window.
10
This produces the cursor Location/Value box, which tell you information of the pixel the cursor
is on.
The 1st line tells you the column and row of the
pixel, and the RGB value of the pixel
The 2nd 4th lines tells you the projection and
datum the image and also provides the map
coordinates
The 5th line gives you the data value of the pixel
By moving the cursor between the two displays, the cursor location/value box will change
depending which image is selected.
However, this is not very helpful, is you want to actually compare to exact pixel values. To do
this Press: Tools/Link/Link Displays from the main image menu bar:
Now when you move the cursor around either image the values of both the images will be
displayed in the Cursor Location/Value box.
11