Title: Twas the Lecture Before Holiday Break
1Twas the Lecture Before Holiday Break
- Readings
- Present
- Makefiles
- Image Array Manipulation and I/O
- Simple Widget Programs
2Holiday Reading
- The Cuckoos Egg (Gift Quiz Material)
- References for doing homework and final project
- Gumley Chapters
- 2, 3.1-3.2,4.1-4.4 (programming)
- 7.1-7.5 (displaying images)
- 9.1-9.3 (GUI programming)
- UNIX Power Tools Chapters
- 48-51
3netpbm.tgz
- netpbm.tgz
- This is the package that contains the entire
PBMPLUS (also known as netpbm) and is distributed
in a format known as - Compressed TAR File
- or
- gzipped TAR file
4present.tgz
- To illustrate how to process these types of
files, there is a file called simpler file
(present.tgz) which can be accessed via anonymous
ftp from - ftp ftp.cis.rit.edu
5Anonymous ftp session login
- ftp ftp.cis.rit.edu
- Name (ftp.cis.rit.edurvrpci) anonymous
- 331 Guest login ok, send your complete e-mail
address as password. - Password
6Most important ftp command
7ftp session change directory
- ftpgt cd people/rolo/simg726
- 250 "/people/rolo/simg726" is new cwd.
- ftpgt ls
- 200 PORT command successful.
- 150 Opening ASCII mode data connection for
/bin/ls. - Makefile_example.tgz
- fortran_stats.tgz
- present.tgz
- 226 Listing completed.
- 54 bytes received in 0.015 seconds (3.50
Kbytes/s)
8ftp file transfer type
- ftpgt ascii
- 200 Type okay.
- ftpgt binary
- 200 Type okay.
9ftp getting a single file
- ftpgt get present.tgz
- 200 PORT command successful.
- 150 Opening ASCII mode data connection for
present.tgz (1211 bytes). - 226 Transfer completed.
- local present.tgz remote present.tgz
- 1219 bytes received in 0.015 seconds (80.45
Kbytes/s)
10Getting multiple files
- ftpgt prompt
- Interactive mode off.
- ftpgt hash
- Hash mark printing on (8192 bytes/hash mark).
- ftpgt mget .tgz
- 200 PORT command successful.
- 150 Opening ASCII mode data connection for
Makefile_example.tgz (31544 bytes). -
11Getting out of ftp
12Most common ftp mistake
- Sending a binary file under ASCII mode
- Result
- Characters not conforming to the ASCII character
set are removed - ALWAYS
- Check the size of the source file and the
transferred file
13Uncompressing and UnTAR
- To uncompress the file
- gunzip present.tgz
- To extract the contents of the tar file
- tar xvf present.tar
- Challenge - look at the file xmas.c and figure
out what it does - cd present
- more xmas.c
14Compiling the Package
- To compile or build the package, a Makefile is
typically present which is an automatic mechanism
to compile all the files and place them in the
proper locations - make
- To run the program
- xmas
15What is a Makefile
- A makefile is a description of how to build
things in UNIX - Automates the creation of stuff
- It is different from a script or batch file
- Describes the relationship of components to the
resulting object - Keeps track of intermediate results and their age
16Other Makefile examples
- Makefile_example.tgz
- Fortran_stats.tgz
17Makefile_example
- Take a raw file -gt convert to pgm image
- Take pgm image -gt rotate image
- Take rotated image -gt label image
- Makefiles work on file dependencies
18Mmakefile
- more Makefile
- MyCat_labeled.pgm MyCat_rotated.pgm label.dat
- ppmlabel -x 0 -y 200 -file label.dat
MyCat_rotated.pgm gt MyCat_labeled.pgm - MyCat_rotated.pgm MyCat.pgm
- pnmrotate 45 MyCat.pgm gt
MyCat_rotated.pgm - MyCat.pgm MyCat.raw
- rawtopgm 256 256 MyCat.raw gt MyCat.pgm
- clean
- rm MyCat_labeled.pgm MyCat_rotated.pgm
MyCat.pgm
19If a file is out of date
- If you edit a file and update it, the makefile
will know - Example
- Edit label.dat to some other new text
- Type make again
- Look at the image
20Fortran_stats example
- Compile a fortran program that computes the mean
of 1,2,3,4,5 - To compile the program
- make
- To run the program
- stats
21Fortran_stats
- more Makefile
- stats main.o sum.o mean.o
- g77 -o stats main.o sum.o mean.o
- main.o main.f
- g77 -c main.f
- sum.o sum.f
- g77 -c sum.f
- mean.o mean.f
- g77 -c mean.f
- clean
- rm .o
22Fortran_stats
- more Makefile
- FORTRAN g77
- stats main.o sum.o mean.o
- (FORTRAN) -o stats main.o sum.o mean.o
- main.o main.f
- (FORTRAN) -c main.f
- sum.o sum.f
- (FORTRAN) -c sum.f
- mean.o mean.f
- (FORTRAN) -c mean.f
- clean
- rm .o
23Typical unreadable makefile
- more makefile
- FORTRAN g77
- OBJS main.o mean.o sum.o
- .f.o
- (FORTRAN) -c .f
- stats (OBJS)
- (FORTRAN) -o stats (OBJS)
- clean
- rm .o
24Array Manipulation and I/O
25Array Manipulation in IDL
- Lets create an array representing a multiband
image - IDLgt imagebindgen(2,3,4)
- IDLgt print,image
- 0 1
- 2 3
- 4 5
26Array Manipulation in IDL
- image continued
- 6 7
- 8 9
- 10 11
- 12 13
- 14 15
- 16 17
27Array Manipulation in IDL
- image continued
- 18 19
- 20 21
- 22 23
28Array Manipulation in IDL
- Extract the first and last band of the image
- IDLgt print,image(,,0)
- 0 1
- 2 3
- 4 5
- IDLgt print,image(,,3)
- 18 19
- 20 21
- 22 23
29Array Manipulation in IDL
- Extract the first and last band of the image
simultaneously - IDLgt print,image(,, 0,3 )
- 0 1
- 2 3
- 4 5
- 18 19
- 20 21
- 22 23
30Array Manipulation in IDL
- Extracting the color or spectral vector of
the first pixel - IDLgt print,image(0,0,)
- 0
- 6
- 12
- 18
31Array Manipulation in IDL
- Assign band 1 to band 4
- IDLgt band1image(,,0)
- IDLgt image(,,3) band1
- Shortcut
- IDLgt image(,,3)image(,,0)
32Array Manipulation in IDL
- Subsectioning parts of an image
- IDLgt print,image(01,01,)
- 0 1
- 2 3
- 6 7
- 8 9
- 12 13
- 14 15
- 0 1
- 2 3
33Array Manipulation
- where function to find indices of elements that
meet certain criteria - IDLgt print, where( image gt 5 and image lt 12)
- Use of other arrays to index other arrays
- IDLgt indiceswhere(image gt 5 and image lt 12)
- IDLgt image(indices)-1
34Reading Writing Data Files in IDL
35Reading Writing Data Files
- IDL can read many types of file formats
- Files can be categorized into two general types
- Formatted ( Readable Text Numbers, ASCII)
- Unformatted( Images)
36Reading Writing Data Files
- The three IDL commands we can use for opening
files are as follows - openr (open a file for reading)
- openw (open a file for writing)
- openu (open a file for reading/writing)
37sample_data_1.dat
- 0 1
- 2 3
- 4 5
- 6 7
- 8 9
- 10 11
38Syntax for Opening Data Files
- Example command for opening a file for input
- IDLgt openr, 1, sample_data_1.dat
- The argument 1 is referred to as the logical unit
number (also known as a file handle) - sample_data_1.dat is the input file name
39Reading the Data
- Need to allocate the array to read in the data
- IDLgt afltarr( 12)
- OR
- IDLgt afltarr( 2, 6)
- Read in the data using the readf statement
- IDLgt readf, 1, a
40Closing the Data File
- To close the data file you can give the following
command - IDLgt close, 1
- A common mistake is to try to open a file(s) that
is already open causing the error - OPENR File unit is already open 1.
- Execution halted at MAIN (OPENR)
- Solution
- IDLgt close, /all
41Putting it all together
- IDLgt openr, 1, sample_data_1.dat
- IDLgt a fltarr( 2,12)
- IDLgt readf, 1, a
- IDLgt close, 1
- IDLgt print, a
42Another Way of Reading in a File
- IDLgt openr, lun, sample_data_1.dat,
- /get_lun
- IDLgt a fltarr( 2, 6 )
- IDLgt readf, lun, a
- IDLgt free_lun, lun
- IDLgt print, a
43Yet Another Way
- IDLgt file_name sample_data_1.dat
- IDLgt a fltarr( 2, 6 )
- IDLgt openr, lun, file_name, /get_lun
- IDLgt readf, lun, a
- IDLgt free_lun, lun
- IDLgt print, a
44To Output a Formatted File
- IDLgt b bindgen( 3, 2)1042
- IDLgt openw, lun, test_output.dat,
- /get_lun
- IDLgt printf, lun, b
- IDLgt free_lun, lun
45test_output.dat
46To Output an Unformatted File
- IDLgt b bindgen( 3, 2)1042
- IDLgt openw, lun, test_output.dat,
- /get_lun
- IDLgt writeu, lun, b
- IDLgt free_lun, lun
47test_output.dat
- 4gtHR\
- Why? Because ...
- - has an ASCII value of 42 decimal
- 4 - has an ASCII value of 52 decimal
- gt - has an ASCII value of 62 decimal
- H - has an ASCII value of 72 decimal
- R - has an ASCII value of 82 decimal
- \ - has an ASCII value of 92 decimal
48test_P2_image.pgm
- P2
- 3 2
- 255
- 42 52
- 62 72
- 82 92
49test_P5_image.pgm
50Testing Out Your or Somebody Elses Image I/O
Routines
- Read in a small test image
- IDLgt aRead_P2_Image(test_input.pgm)
- Write out the small test image
- IDLgt Write_P2_Image,test_output.pgm,a
- Read in the small test image you just wrote
- IDLgt bRead_P2_Image(test_output.pgm)
- Statistics (sum, mean, etc.) must be equal
- Finally, sum_squares( a - b ) must be 0.0
51Multiband Image Pixel Ordering
- Band Sequential
- array( column, row, band)
- array( sample, line, band)
- Band Interleaved by Line
- array( column, band, row )
- array( sample, band, line)
- Band Interleaved by Pixel
- array( band, column, row )
- array( band, sample, line )
52Multiband Image Pixel Ordering
- Let us take the following file
- test_data.dat
- 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20 21 22 23 - And look at the different interleaving
representations as a multiband image.
53Band Sequential Example
- If we read in the test_data.dat using the array
defined as abindgen(2,3,4), we would get - Band 0 Band 1 Band 2 Band 3
- 0 1 6 7 12 13 18 19
- 2 3 8 9 14 15 20 21
- 4 5 10 11 16 17 22 23
54Band Interleaved by Line
- If we read in test_data.dat using the array
defined as abindgen(2,4,3), we would get - Band 0 Band 1 Band 2 Band 3
- 0 1 2 3 4 5 6 7
- 8 9 10 11 12 13 14 15
- 16 17 18 19 20 21 22 23
55Band Interleaved by Pixel
- If we read in test_data.dat using the array
defined as abindgen(4,2,3), we would get - Band 0 Band 1 Band 2 Band 3
- 0 4 1 5 2 6 3 7
- 8 12 9 13 10 14 11 15
- 16 20 17 21 18 22 19 23
56Reform/Transpose Conversion
- To convert previous examples from BSQ to BIL, we
can use the following command - Assume a BSQ image abindgen(2,3,4)
- IDLgt b reform( a, 2, 4, 3 )
- IDLgt c transpose( b, 0, 2, 1 )
- The image c is now a BIL image
57Reform/Transpose Conversion
- To convert previous examples from BSQ to BIP, we
can use the following command - Assume a BSQ image abindgen(2,3,4)
- IDLgt b reform( a, 4, 2, 3 )
- IDLgt c transpose( b, 1, 2, 0 )
- The image c is now a BIP image
58Widget Programming
59Widget
- What is a widget?
- It is a graphical user interface component
- Basic IDL Widget Toolkit
- Widget_Base, Widget_Button
- Widget_Draw, Widget_DropList
- Widget_Label, Widget_List
- Widget_Slider, Widget_Text
60Widget_Base
- This widget type is used to hold other widget
types. You can think of this as your blank
canvas. It is also known as the parent window
in other terms. - To invoke a widget base, you would give the
following commands - IDLgt base Widget_Base()
- IDLgt Widget_Control, base, /realize
61What the IDL Commands Mean
- base Widget_Base()
- In this function call, base will contain a unique
identifier (ID) to this specific instance of a
blank window. The window is still described in
memory, but not displayed - Widget_Control, base, /realize
- This tells IDL to display the entity with the ID
value in the variable base
62Result of the Widget_Base
- You should see a blank window similar to the one
below
63Other Widget Types
- To invoke a Widget_Button
- IDLgt button1 Widget_Button( base )
- IDLgt Widget_Control, base, /realize
64To Change the Title of a Button Widget
- IDLgtWidget_Control,button1,Set_ValueOK
65Destroying a Widget
- IDLgt Widget_Control,button1,/destroy
66To Destroy the Base Widget
- IDLgt Widget_Control,base,/destroy
- If there are any widgets attached to the base,
those children widgets will also be destroyed.
67Other Widget Examples
- IDLgt basewidget_base(column1)
- IDLgt buttonwidget_button(base)
- IDLgt labelwidget_label(base)
- IDLgt widget_control,base,/realize
68Other Widget Examples
- IDLgt base1widget_base(column1)
- IDLgt list1widget_list(base1)
- IDLgt slider1widget_slider(base1)
- IDLgt widget_control, base1, /realize
69Adding to the Previous Example
- IDLgt base2widget_base(base1,row2)
- IDLgt button1widget_button(base2, value"First
Button") - IDLgt button2widget_button(base2, value"Second
Button") - IDLgt widget_control,base1,/realize
70Modifying Previous Example
- IDLgt widget_control,slider1,set_value100
- IDLgt widget_control,base1,/realize
- IDLgt widget_control,button2,set_value
- "Last Button"
71Getting Information from a Widget
- IDLgtwidget_control,button1,get_valuebutton_value
- IDLgtprint,button_value
- First Button
72Have a Safe and Happy Holiday
- Remember, friends dont let friends program drunk