Rolando V. RaqueñoSaturday, June 27, 2015 1 Quiz #6 Topics cut paste sort tail head.

Post on 21-Dec-2015

215 views 2 download

Tags:

transcript

Rolando V. Raqueño Tuesday, April 18, 202311

Quiz #6 Topics

• cut• paste• sort• tail• head

Rolando V. Raqueño Tuesday, April 18, 202322

Numbering SystemsDECIMAL BINARY OCTAL HEXADECIMAL(Base 10) (Base 2) (Base 8) (Base 16)

0 0 0 01 1 1 12 10 2 23 11 3 34 100 4 45 101 5 56 110 6 67 111 7 78 1000 10 89 1001 11 910 1010 12 A11 1011 13 B12 1100 14 C13 1101 15 D14 1110 16 E15 1111 17 F

Rolando V. Raqueño Tuesday, April 18, 202333

Converting Between Bases

• 42 base 10 converted to base 10,

• 42 base 10 converted to base 8,

4210 4 101 40 2 100 2 4210

4210 5 81 40 2 80 2 528

Rolando V. Raqueño Tuesday, April 18, 202344

Converting Between Bases

• 42 base 10 converted to base 2,

• 42 base 10 converted to base 16,

4210 125 32 0 24 0 123 8 0 22 0 121 2 0 20 0 1010102

4210 2 161 32 a 160 10 2a16

Rolando V. Raqueño Tuesday, April 18, 202355

Number Base Conversion using bc

• To convert decimal to binaryobase=242101010

• To convert octal to hexadecimalobase=16ibase=8522A

Rolando V. Raqueño Tuesday, April 18, 202366

Negative Number Representation

DECIMAL DECIMAL BINARY(Base 10) (4-digit) (4-digit)

-8 9992 1000-7 9993 1001-6 9994 1010-5 9995 1011-4 9996 1100-3 9997 1101-2 9998 1110-1 9999 11110 0 00001 1 00012 2 00103 3 00114 4 01005 5 01016 6 01107 7 0111

Rolando V. Raqueño Tuesday, April 18, 202377

Converting a Negative Number into Binary using 2’s Complement

• To convert -42 into a negative binary value – Determine the number of bits to represent (e.g.

16 bits)– Convert the absolute value (42) into binary

0000000000101010

– Take the 1’s complement of the number1111111111010101

– Add 1 to the number1111111111010110

Rolando V. Raqueño Tuesday, April 18, 202388

Floating Point Representation

• Sets of bits are separated into – mantissa

– exponent field

Rolando V. Raqueño Tuesday, April 18, 202399

Another Example of Unformatted Output (e.pro)

pro e

openw, lun, 'e.dat', /get_lun e = exp(1.0) writeu,lun, e free_lun, lun

end

Rolando V. Raqueño Tuesday, April 18, 20231010

Octal Interpretation of e.dat (big endian)

% od -b e.dat0000000 100 055 370 1240000004

Rolando V. Raqueño Tuesday, April 18, 20231111

Binary Interpretation of e.dat (big endian)

% bc -lobase=2ibase=8100100000055101101370111110001241010100

Rolando V. Raqueño Tuesday, April 18, 20231212

Binary Interpretation of e.dat (big endian)

01000000 00101101 11111000 01010100

Rolando V. Raqueño Tuesday, April 18, 20231313

(SINGLE PRECISION) - IEEE (ANSI/IEEE Std 754-

1985)

+-+--------+-----------------------+ |S| exp | fraction | +-+--------+-----------------------+ ^ ^ Bit31 Bit0

A formula that gives the value of this float is:

Value=(-1)**S X 1.fraction X 2**(exp-127)

Rolando V. Raqueño Tuesday, April 18, 20231414

Binary Interpretation of e.dat (big endian)

01000000 00101101 11111000 01010100

[Bit 31]S = 0[Bits 30:23] exp = 1000000 0 = 128 (decimal)[Bits 22:0]fraction = 0101101 11111000 01010100

Rolando V. Raqueño Tuesday, April 18, 20231515

(SINGLE PRECISION) - IEEE (ANSI/IEEE Std 754-

1985)Value=(-1)**S X 1.fraction X 2**(exp-127)

2**(128-127)= 2

% bc -libase=21.0101101 11111000 010101001.35914087295532226562500ibase=10102*1.359140872955322265625002.71828174591064453125000

Rolando V. Raqueño Tuesday, April 18, 20231616

Floating Point Interpretation of e.dat (big endian)

% od -f e.dat0000000 2.7182817e+000000004

Rolando V. Raqueño Tuesday, April 18, 20231717

Debugging in IDL

Rolando V. Raqueño Tuesday, April 18, 20231818

Basic IDL Debugging Commands

breakpoint

.step (.s)

.stepover (.so)

.continue

.return

.out

Rolando V. Raqueño Tuesday, April 18, 20231919

mean.pro

10 ;- 11 ;

12 function mean,x

13 n = n_elements(x)

14 answer = sum(x)/double(n)

15 return, answer

16 end

Rolando V. Raqueño Tuesday, April 18, 20232020

Breakpoints

IDL> breakpoint, ‘mean.pro’, 12

IDL> help,/breakpoint

Breakpoints:

Index Module Line File

----- ------ ---- ----

0 MEAN 12 mean.pro

IDL> breakpoint, /clear, 0

OR

IDL> breakpoint, /clear, ‘mean.pro’, 12

Rolando V. Raqueño Tuesday, April 18, 20232121

.step

• Used after a breakpoint is reached

• Single step through commands

• If statement is a function or procedure– Will enter into it

Rolando V. Raqueño Tuesday, April 18, 20232222

.stepover

• Similar to .step • Executes functions and procedures to

completion without stopping inside the function

Rolando V. Raqueño Tuesday, April 18, 20232323

.return

• Continues execution until a return statement is encountered.

• Useful in checking the return value of an inner (nested) function in a function composition

• e.g.

sqrt(variance(x))

Rolando V. Raqueño Tuesday, April 18, 20232424

.out

• Continues execution out of the current routine.

• Useful in leaving a routine that you stepped into, but have determined that all is working properly and want to return to the calling routine.

Rolando V. Raqueño Tuesday, April 18, 20232525

mean.pro

10 ;- 11 ; 12 function mean,x 13 n = n_elements(x) 14 answer = sum(x)/double(n) 15 return, answer 16 end

Rolando V. Raqueño Tuesday, April 18, 20232626

Mystery Images

Rolando V. Raqueño Tuesday, April 18, 20232727

Given an image of unknown origin

• Dimensions of the image?– Most importantly the number of samples

• Aspect ratio of the image? • Number of bytes per pixel?• Number of bands of the image?• Number of bits per pixel?• External or internal compression applied

– gzip– tiff or jpeg

Rolando V. Raqueño Tuesday, April 18, 20232828

Know the imaging instrument

• Find out what kind of image capture device– Framing Camera with filters

• Band Sequential Images (BSQ)

– Flatbed of Pushbroom scanner• Band interleaved by line (BIL)

– Line Scanner• Band interleaved by pixel (BIP)

Rolando V. Raqueño Tuesday, April 18, 20232929

Tools at your disposal for dissecting the image

% file% anytopnm % more% ls -l% bc -l% od% dd% strings% rawtopgm or cat% xv

Rolando V. Raqueño Tuesday, April 18, 20233030

file

• Uses information in /etc/magic to determine the type of a file.

• Common outputs from the file command% file irod.img.gz

irod.img.gz: gzip compressed data - deflate method , original file name , max compression

% file readme

readme: ascii text

Rolando V. Raqueño Tuesday, April 18, 20233131

File (more examples)

% file RIT_bip.imgRIT_bip.img: data

% file modtran4.batmodtran4.bat: executable c-shell script

bean% file maincode.exemaincode.exe: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not stripped

Rolando V. Raqueño Tuesday, April 18, 20233232

File (image examples)Don’t always believe the extensions

bean% file feep.tif

feep.tif: TIFF file, big-endian

bean% file feep.pgm

feep.pgm: PGM ascii file

bean% file AVIRIS_RIT.jpg

AVIRIS_RIT.jpg: JPEG file

bean% file rotate.pbm

rotate.pbm: PGM raw file

Rolando V. Raqueño Tuesday, April 18, 20233333

anytopnm

• Shell script that does a brute force test on images and converts to pnm format

% anytopnm mystery_file > mystery_file.pnm

Rolando V. Raqueño Tuesday, April 18, 20233434

od

• Can be used to quickly check the minimum and maximum values in a file

• Stupid UNIX Trick% od –d –v image.raw | cut –c10- | tr –s “ “ “\012” | sort –nu | head

Rolando V. Raqueño Tuesday, April 18, 20233535

Xv and NetPBM

• Xv want multi-byte NetPBM files in little-endian form

• N.B. NetPBM utilities behave inconsistently for multi-byte data

Rolando V. Raqueño Tuesday, April 18, 20233636

Can you guess the dimensions of the image?

• Try to guess the number of rows (width) first.– Possible guesses

•256•512•2^n•2^n+2^(n-1)

Rolando V. Raqueño Tuesday, April 18, 20233737

Can you guess the aspect ratio of the image?

• wc -c or ls -l – determine how many bytes are in the image

• Square root of the image size – Multiple of a perfect square

• Assume that the image is greyscale & square– use rawtopgm

% rawtopgm 512 512 image.raw > image.pgm

Rolando V. Raqueño Tuesday, April 18, 20233838

Square Gray Scale Image

• Used rawtopgm to create a pgm file and then use xv to display

Rolando V. Raqueño Tuesday, April 18, 20233939

A convenient little trick

• If you are just experimenting with a mystery image

% rawtopgm 512 512 image.raw | xv -

Rolando V. Raqueño Tuesday, April 18, 20234040

Does it have a header?

• Not a perfect square– go ahead and try to display it as if it were a

square image to see if it has a header.

Rolando V. Raqueño Tuesday, April 18, 20234141

Square Grey Scale image with a header

• This structure means you have a header in the file that is causing a uniform shift

• You can fix this by using dd

Rolando V. Raqueño Tuesday, April 18, 20234242

Square image no header

• Your guess on the width of the image is short by one pixel

Rolando V. Raqueño Tuesday, April 18, 20234343

Square image no header

• Your guess on the width of the image is long by one pixel

Rolando V. Raqueño Tuesday, April 18, 20234444

Square image no header

• You probably guessed a little too low on the width of this image

• (off by 6 pixels)

Rolando V. Raqueño Tuesday, April 18, 20234545

Square Image with no header

• Your probably guessed a little too high on the width of the image

• (off by 6 pixels)

Rolando V. Raqueño Tuesday, April 18, 20234646

A color image displayed as greyscale image

• Correct dimensions– 256x256x3 BIP

• Incorrectly assumed– 443x443 image with

header

• N.B. 196608/3=256^2

• Indicates a multiband image

Rolando V. Raqueño Tuesday, April 18, 20234747

Multiband Assumption

• Once multiband image is assumed– Need to determine interleaving– Can be deduced by displaying first band– This assumes you have a guess of image

dimension

• Extract the first band out using dd

Rolando V. Raqueño Tuesday, April 18, 20234848

First band of color image file assumed to be BSQ

• Assume a square image for first band

• Color image file obviously not BSQ

Rolando V. Raqueño Tuesday, April 18, 20234949

Square color image displayed as a greyscale (3:1 aspect ratio)

• Original image 3x256x256

• Displayed it as a greyscale 768x256

• To get insight into interleaving structure.

• BIP file would look like the left image

Rolando V. Raqueño Tuesday, April 18, 20235050

Square color image displayed as greyscale( 3:1 aspect ratio)

• This is how a BIL image would behave• What we have here is the individual bands

side by side

Rolando V. Raqueño Tuesday, April 18, 20235151

• This is how a BSQ file would behave

Square color image displayed as greyscale( 3:1 aspect ratio)

Rolando V. Raqueño Tuesday, April 18, 20235252

Multibyte pixel image

• Need to be careful about the endian of the machine on which the image was written

• Can use dd to swap bytes for short integer images (2-bytes per pixel) or the swap_endian function in IDL

Rolando V. Raqueño Tuesday, April 18, 20235353

Mystery Image Examples

• Check Webpage for sources of examples.

• An example will be given for the midterm exam.