Download Lecture_3

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Lecture 3: Matlab Fundamentals: computer representation, data classes, image display and types
Learning Objectives:
 Number representation and data classes in Matlab
 Data storage and image headers
 Create and scale display of a test image in Matlab
 Identify basic image types using Matlab internal test images
Assignment:
1. Read pages 34-42 in Chapter 1 of “Numerical Computing with Matlab,” by Cleve Moler
(http://www.mathworks.com/moler/intro.pdf).
I.
a.
Number representation in Matlab
Default is “double precision floating point”
i. IEEE standard
ii. Recall that most of the Real numbers are not computable.
a. This would require infinite precision and unlimited computer memory.
b. Practically, Real number operations are approximated within finite
memory registers.
x=±(1+f)∙2e
f ≡ mantissa, 0≤f<1. Determines precision
e ≡ exponent. Determines range
Single precision (SP): 32 bit (4 bytes): 23 bit mantissa, 1 bit sign, 8 bit
exponent.
Double precision (DP): 64 bit (8 bytes): 52 bit mantissa, 1 bit sign, 11 bit
exponent.
What does this mean in practical terms?
SP: The product 223f is an integer in the interval 0≤223f<223, -127≤e<128.
DP: The product 252f is an integer in the interval 0≤252f<252, -1023≤e<1024.
The sign of the exponent is handled by offsetting the exponent by 1023 for DP
and by 255 for SP.
Examples:
Consider a simple example where 3 bits are used to represent f, and the range of
the exponent is -4≤e<3 (also a 3 bit number).
Lecture 3: Matlab Fundamentals: computer representation, data classes, image display and types
What is the smallest positive number that can be represented for this specific
example?
s:[0] f:[0 0 0] e:[0 0 1]
+
1
∙
2-4
= 2-4 = 1/16,
where we have offset the exponent by 4 to represent it as a positive binary
number.
What is the largest positive number that can be represented?
s:[0] f:[1 1 1] e:[1 1 1]
+
1.875 ∙
23
= 15.
23f is an integer in the range 0≤23f<23. For maximum mantissa, then 23f = 7,
which implies f = 7/8, and 1+f = 1.875.
What is the increment between numbers?
s:[0] f:[0 0 1] e:[0 0 1]
+
1.125 ∙ 2-4 = 2-4 = 9/128.
Increment between small positive and next largest number is 9/128-1/16 = 1/128.
s:[0] f:[1 1 0] e:[1 1 1]
+
1.75
∙
23
= 14.
Increment between largest positive and next smallest number is 15-14 = 1.
What is the fundamental resolution of this number representation?
Intuitively we notice that f is changing in increments of 1/8. Consider the
distance from 1 to the next largest floating point number:
s:[0] f:[0 0 0] e:[1 0 0] = 1
s:[0] f:[0 0 1] e:[1 0 0] = 1.125
Increment is 2-3 = 1/8. This is the definition of the “machine epsilon (eps).”
It is a measure of the numerical precision of the floating point representation
of the machine.
What is eps for SP floating point number representation?
SP: f is represented by 24 bits implies that eps = 2-23.
DP: f is represented by 52 bits implies that eps = 2-52.
II.
Data classes
a. Double and single fpn
b. uint8, uint16, uint32
int: [1 1 1 1 1 1 1 1] = 8 bits of memory or 1 byte
27+26+25+24+23+22+21+20 = 128+64+32+16+8+4+2+1 = 255, range [0, 255].
uint16 –> 16 bits or 2 bytes [0, 65535]
uint32 -> 32 bits or 4 bytes [0, 4294967295]
Lecture 3: Matlab Fundamentals: computer representation, data classes, image display and types
c. Int8, int16, int32
s:[0] int:[1 1 1 1 1 1 1] = 64+32+16+8+4+2+1 = 127, range [-128, 127]
int16 –> 16 bits or 2 bytes [-32768, 32767]
int32 -> 32 bits or 4 bytes [-2147483648, 2147483647]
d. Char
i. Unicode representation -> 2 bytes per element
e. Logical (Binary)
i. 1 byte per element
III.
Data Storage
a. Big and little Endian (“Byte order” or “byte swapping:”)
i. Data storage
1. memory address begins with most significant byte (MSB) =
“Little endian”
2. memory address begins with least significant byte (LSB) =
“Big endian”
Consider a 2-byte (16 bit) integer depicted by the brackets below:
[MSB...(byte 1)][(byte2)...LSB]
Endian)
Address:
...
2
1
Or, after reflection, or swapping of the bytes
[(byte 2)...LSB][MSB...(byte 1)]
Address:
...
2
1
(Little
(Big Endian)
http://www.ittvis.com/services/techtip.asp?ttid=1804
b. Real vs. Complex data storage
i. Recall that the complex numbers are displayed as a single number
in the Matlab interface
ii. However, Matlab and other image processing languages actually
store complex data as 2 vectors (or arrays) of double precision
numbers
1. Real matrices require only a single vector or array.
2. Often an additional vector stores the dimensions (N,M) of
the matrix or image size; this vector can be stored with
the data in a structure called a “header.”
Lecture 3: Matlab Fundamentals: computer representation, data classes, image display and types
c. “Raw” Images vs. Specific image formats (“Headers”)
i. Raw image data is stored without a header
ii. Conventional file formats such as “bitmap” have “headers”
1. The Header is usually a structure formatted with a “field”
and value associated with that field.
2. The fields and values might describe the matrix size, type
of image (i.e. intensity vs. RGB or color), compression
used etc…
Consider an example of the Digital Imaging and Communications in Medicine
(DICOM) format standard. The header contains specific information about the
image data that follows (Figure 1a). Specific memory addresses (or fields) in
the header contain a range of information including, matrix size, data class,
image type, and default display options.
Figure 1a
Figure 1b
http://www.sph.sc.edu/comd/rorden/dicom.html#header