part 3 basic concepts of image processingcanerozcan.net/files/cme429/cme429_week3.pdf · matlab...
TRANSCRIPT
CME429 Introduction to Image Processing
Assist. Prof. Dr. Caner ÖZCAN
Part 3 Basic Concepts of Image Processing
Those who wish to succeed must ask the right preliminary questions. ~Aristotle
Outline
2
2. Digital Image Fundamentals ►Elements of Visual Perception
►Light and the Electromagnetic Spectrum
►Image Sensing and Acquisition
►Image Sampling and Quantization
►Some Basic Relationships Between Pixels
►An Introduction to the Mathematical Tools Used in Digital Image Processing
►MATLAB Image Processing
Some Basic Relationships Between Pixels
3
►Neighbors of a pixel p at coordinates (x,y)
► 4-neighbors of p, denoted by N4 (p): (x-1, y), (x+1, y), (x,y-1), and (x, y+1).
► 4 diagonal neighbors of p, denoted by ND (p): (x-1, y-1), (x+1, y+1), (x+1,y-1), and (x-1, y+1).
► 8 neighbors of p, denoted N8(p) N8 (p) = N4 (p) U ND (p)
Some Basic Relationships Between Pixels
4
►Adjacency
Let V be the set of intensity values.
In a binary image, if we talk of the adjaceny of the 1-valued pixels, V = {1}.
►4-adjacency: Two pixels p and q with values from V are 4-adjacent if q is in the set N4(p).
►8-adjacency: Two pixels p and q with values from V are 8-adjacent if q is in the set N8(p).
Some Basic Relationships Between Pixels
5
►Adjacency Let V be the set of intensity values At the adjacency of the gray level pixels, the V set is any subset of this 256 value. ►m-adjacency: Two pixels p and q with values from
V are m-adjacent if (i) q is in the set N4(p), or
(ii) q is in the set ND(p) and the set N4(p) ∩ N4(q) has no pixels whose values are from V.
Some Basic Relationships Between Pixels
6
Path ► A (digital) path (or curve) from pixel p with coordinates (x0, y0)
to pixel q with coordinates (xn, yn) is a sequence of distinct pixels with coordinates
(x0, y0), (x1, y1), …, (xn, yn)
Where (xi, yi) and (xi-1, yi-1) are adjacent for 1 ≤ i ≤ n.
► Here n is the length of the path.
► If (x0, y0) = (xn, yn), the path is closed path.
► We can define 4-, 8-, and m-paths based on the type of
adjacency used.
7
0 1 1 0 1 1 0 1 1
0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1
V = {1}
Examples: Adjacency and Path
8
0 1 1 0 1 1 0 1 1
0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1
V = {1}
8-adjacent
Examples: Adjacency and Path
9
0 1 1 0 1 1 0 1 1
0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1
V = {1}
8-adjacent m-adjacent
Examples: Adjacency and Path
10
01,1 11,2 11,3 0 1 1 0 1 1
02,1 12,2 02,3 0 1 0 0 1 0
03,1 03,2 13,3 0 0 1 0 0 1
V = {1, 2}
8-adjacent m-adjacent
The 8-path from (1,3) to (3,3): (i) (1,3), (1,2), (2,2), (3,3) (ii) (1,3), (2,2), (3,3)
The m-path from (1,3) to (3,3): (1,3), (1,2), (2,2), (3,3)
Examples: Adjacency and Path
Distance Measures
11
►Given pixels p, q and z with coordinates (x, y), (s, t), (u, v) respectively, the distance function D has following properties:
D(p, q) ≥ 0 [D(p, q) = 0, iff p = q]
D(p, q) = D(q, p)
D(p, z) ≤ D(p, q) + D(q, z)
Distance Measures
12
►The following are the different Distance measures:
a. Euclidean Distance :
De(p, q) = [(x-s)2 + (y-t)2]1/2
b. City Block Distance:
D4(p, q) = |x-s| + |y-t|
c. Chess Board Distance:
D8(p, q) = max(|x-s|, |y-t|)
Question 5
13
►In the following arrangement of pixels, what’s the value of the chessboard distance between the circled two points?
0 0 0 0 0
0 0 1 1 0
0 1 1 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
Question 6
14
►In the following arrangement of pixels, what’s the value of the city-block distance between the circled two points?
0 0 0 0 0
0 0 1 1 0
0 1 1 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
Introduction to Mathematical Operations in DIP
15
►Array vs. Matrix Operation
11 12
21 22
b bB
b b
11 12
21 22
a aA
a a
11 11 12 21 11 12 12 22
21 11 22 21 21 12 22 22
* a b a b a b a b
A Ba b a b a b a b
11 11 12 12
21 21 22 22
.* a b a b
A Ba b a b
Array product
Matrix product
Array product operator
Matrix product operator
Arithmetic Operations
16
►Arithmetic operations between images are array operations. The four arithmetic operations are denoted as
s(x,y) = f(x,y) + g(x,y)
d(x,y) = f(x,y) – g(x,y)
p(x,y) = f(x,y) × g(x,y)
v(x,y) = f(x,y) ÷ g(x,y)
Example: Addition of Noisy Images for Noise Reduction
17
Noiseless image: f(x,y)
Noise: n(x,y) (at every pair of coordinates (x,y), the noise is uncorrelated and has zero average value)
Corrupted image: g(x,y)
g(x,y) = f(x,y) + n(x,y)
Reducing the noise by adding a set of noisy images, {gi(x,y)}
1
1( , ) ( , )
K
i
i
g x y g x yK
Example: Addition of Noisy Images for Noise Reduction
18
►In astronomy, imaging under very low light levels frequently causes sensor noise to render single images virtually useless for analysis.
►In astronomical observations, similar sensors for noise reduction by observing the same scene over long periods of time. Image averaging is then used to reduce the noise.
Example: Addition of Noisy Images for Noise Reduction
19
An Example of Image Subtraction: Mask Mode Radiography
20
Mask h(x,y): an X-ray image of a region of a patient’s body
Live images f(x,y): X-ray images captured at TV rates after injection of the contrast medium
Enhanced detail g(x,y)
g(x,y) = f(x,y) - h(x,y)
The procedure gives a movie showing how the contrast medium propagates through the various arteries in the area being observed.
An Example of Image Subtraction: Mask Mode Radiography
21
An Example of Image Subtraction: Mask Mode Radiography
22
An Example of Image Multiplication
23
An Example of Image Multiplication
24
MATLAB Image Processing
25
►The Image Processing Toolbox is a collection of functions that extend the capabilities of the MATLAB’s numeric computing environment. The toolbox supports a wide range of image processing operations, including: Geometric operations
Neighborhood and block operations
Linear filtering and filter design
Transforms
Image analysis and enhancement
Binary image operations
Region of interest operations
MATLAB Image Processing
26
►MATLAB can import/export several image formats: BMP (Microsoft Windows Bitmap)
GIF (Graphics Interchange Files)
HDF (Hierarchical Data Format)
JPEG (Joint Photographic Experts Group)
PCX (Paintbrush)
PNG (Portable Network Graphics)
TIFF (Tagged Image File Format)
XWD (X Window Dump)
raw-data and other types of image data
MATLAB Image Processing
27
►Data types in MATLAB Double (64-bit double-precision floating point)
Single (32-bit single-precision floating point)
Int32 (32-bit signed integer)
Int16 (16-bit signed integer)
Int8 (8-bit signed integer)
Uint32 (32-bit unsigned integer)
Uint16 (16-bit unsigned integer)
Uint8 (8-bit unsigned integer)
MATLAB Image Processing
28
MATLAB Image Processing
29
MATLAB Image Processing
30
MATLAB Image Processing
31
MATLAB Image Processing
32
MATLAB Image Processing
33
MATLAB Image Processing
34
MATLAB Image Processing
35
MATLAB Image Processing
36
► Indexing in vectors
>>If the vector v = [1 3 5 7 9] is written and ENTER is pressed
v =
1 3 5 7 9
>>If v(2) is written and ENTER is pressed, the second element of vector v is assigned to ans variable:
ans =
3
A row vector is returned with a column transpose marker ('):
>> w = v’
w =
1
3
5
7
9
MATLAB Image Processing
37
► Indexing in vectors
>> v(1:3) is written and ENTER is pressed elements 1 to 3 of the vector V are taken.
ans =
1 3 5
If you want to retrieve the vector from the 2nd to the 4nd element:
>> v(2:4) Result:
ans =
3 5 7
If you want to retrieve all the elements from the 3nd element of the vector v:
>> v(3:end) Result:
ans =
5 7 9
MATLAB Image Processing
38
► Indexing in vectors
When starting from the first element of the vector and asking all the elements from the first to the last, the following command is obtained:
>> v (1:2:end)
ans =
1 5 9
>> v (end:-2:1) creates the elements of the vector in reverse by jumping from the last element to the first element. Result:
ans =
9 5 1
MATLAB Image Processing
39
► Indexing in vectors
>> x = linspace (a, b, n)
will form a vector consisting of n numbers starting at a and ending at b and equally spaced.
- If we want to select the first, fourth and fifth elements of vector v:
>> v([1 4 5])
ans =
1 7 9
MATLAB Image Processing
40
► Indexing in matrices
Matrices are formed by separating line vectors within square brackets with semicolons.
>> A=[ 1 2 3 ; 4 5 6 ; 7 8 9 ]; % creates a 3x3 matrix.
If you want to find the element in column 3 of row 2 in matrix A
>> A(2,3); % 6
>> C = A( : , 3) ; % ( : ) selects the elements in blocks, here all the rows but only the
third column. It will only give us the 3rd column elements. Another way is to show
>> A(1:3,3) ;
>> T2 = A(1:2 , 1:3) ; % selects the first two rows and three columns.
>> A ( : , 2 ) = 1; % Only the second column elements in all rows of matrix A are set to 1.
MATLAB Image Processing
41
► Indexing in matrices
Sample question: How can we make a matrix B whose third column is 0, but whose
other columns are equal to A?
Answer: >> B = A ;
>> B ( : , 3 ) = 0 ;
>> A(end , end ) ; % the end statement indicates the last item in the last row and the
last column, where the third row has 9 in the third column.
B = A ( : ) % Order all the elements of the matrix A as a single column. It helps us when
we want to process all the elements of the matrices.
Example ; >> s = sum ( A ( : ) ) ; % In this case it gives the sum of all elements of matrix
A. But only >> sum (A); it would give the column sums separately.
MATLAB Image Processing
42
►Image Operations RGB image to gray image
Image resize
Image crop
Image rotate
Image histogram
Image histogram equalization
Convolution
►Examples (Matlab For Image Processing):
https://www.youtube.com/playlist?list=PL9ADE09052E08CC57
MATLAB Image Processing
43
Performance Issues ►The idea: MATLAB is
very fast on vector and matrix operations Correspondingly slow with loops
►Try to avoid loops ►Try to vectorize your code
►Search (Techniques to Improve Performance):
http://www.mathworks.com/support/tech-notes/1100/1109.html
MATLAB Image Processing
44
MATLAB Image Processing
45
References
46
►Sayısal Görüntü İşleme, Palme Publishing, Third Press Trans. (Orj: R.C. Gonzalez and R.E. Woods: "Digital Image Processing", Prentice Hall, 3rd edition, 2008).
►“Digital Image Processing Using Matlab”, Gonzalez & Richard E. Woods, Steven L. Eddins, Gatesmark Publishing, 2009
►Lecture Notes, MATLAB for Image Processing, CS638-1 TA: Tuo Wang
►Lecture Notes, BIL717-Image Processing, Erkut Erdem
►Lecture Notes, EBM537-Image Processing, F.Karabiber