You are on page 1of 39

General

 Binary
 Gray Scale
 Color
Binary Images

Y
1 1 1 1
Row 1

q
X

0: Black Row q
0 0 0 0 0

1: White p
Gray Level Image

10 5 9

100
Gray Scale Image
Color Image
Red, Green, Blue Channels
Image Histogram
Image Noise

 Light Variations
 Camera Electronics
 Surface Reflectance
 Lens
Image Noise

 I(x,y) : the true pixel values


 n(x,y) : the noise at pixel (x,y)
Iˆx, y   I  x, y   nx, y 


Gaussian Noise

 n2

n  x, y   e 2 2
Image Derivatives & Averages
Definitions

 Derivative: Rate of change


– Speed is a rate of change of a distance
– Acceleration is a rate of change of speed
 Average (Mean)
– Dividing the sum of N values by N
Derivative

df f ( x)  f ( x  x)
 lim x 0  f ( x)  f x
dx x

ds dv
v speed a  acceleration
dt dt
Examples

y  x2  x4 y  sin x  e  x
dy dy
 2 x  4 x3  cos x  (1)e  x
dx dx
Discrete Derivative

df f ( x)  f ( x  x)
 lim x 0  f ( x)
dx x

df f ( x)  f ( x  1)
  f ( x)
dx 1

df
 f ( x)  f ( x  1)  f ( x)
dx
Discrete Derivative
Finite Difference

df
 f ( x)  f ( x  1)  f ( x) Backward difference
dx

df
 f ( x)  f ( x  1)  f ( x) Forward difference
dx

df
 f ( x  1)  f ( x  1)  f ( x) Central difference
dx
Example

f ( x)  10 15 10 10 25 20 20 20
f ( x)  0 5  5 0 15  5 0 0
f ( x)  0 5  10 5 15 20 5 0
Derivative Masks

Backward difference [-1 1]

Forward difference [1 -1]


Central difference [-1 0 1]
Derivatives in 2 Dimensions

Given function f ( x, y )
 f ( x, y ) 
   fx 
Gradient vector f ( x, y )   f (xx, y )    
   fy 
 y 

Gradient magnitude f ( x , y )  f x2  f y2
fx
Gradient direction   tan 1
fy
Derivatives of Images

 1 0 1 1 1 1
1 1
Derivative masks f x   1 0 1 f y   0 0 0 
3 3
 1 0 1  1  1  1

10 10 20 20 20  0 0 0 0 0
10 10 20 20 20 0 10 10 0 0
  
I  10 10 20 20 20 I x  0 10 10 0 0
   
10 10 20 20 20  0 10 10 0 0 
10 10 20 20 20 0 0 0 0 0
Derivatives of Images

10 10 20 20 20 0 0 0 0 0
10 10 20 20 20 0 0 0 0 0
 
I  10 10 20 20 20 I y  0 0 0 0 0
   
10 10 20 20 20 0 0 0 0 0
10 10 20 20 20 0 0 0 0 0
Correlation
f  h   f k , l hi  k , j  l 
k l

f  Image
f  Kernel

f
h
f1 f2 f3 h1 h2 h3 f * h  f1h1  f 2 h2  f 3 h3
f4 f5 f6  h4 h5 h6  f 4 h4  f 5 h5  f 6 h6
f7 f8 f9 h7 h8 h9  f 7 h7  f 8 h8  f 9 h9
Convolution
f * h   f k , l hi  k , j  l 
k l
h
f  Image h7 h8 h9 h1 h2 h3
X  flip
h  Kernel h4 h5 h6 h4 h5 h6
h1 h2 h3 h7 h8 h9

f Y  flip
f1 f2 f3 h9 h8 h7 f * h  f1h9  f 2 h8  f 3 h7
f4 f5 f6  h6 h5 h4  f 4 h6  f 5 h5  f 6 h4
f7 f8 f9 h3 h2 h1  f 7 h3  f 8 h2  f 9 h1
Convolution

f ( x, y )  h  f ( x  1, y  1)h( 1,1)  f ( x, y  1)h(0,1)  f ( x  1, y  1)h(1,1) 


f ( x  1, y )h( 1,0)  f ( x, y )h(0,0)  f ( x  1, y )h(1,0)
f ( x  1, y  1)h( 1,1)  f ( x, y  1)h(0,1)  f ( x  1, y  1)h(1,1)

f 1 1
h
f  h    f ( x  i, y  i )h(i, j )
x i  1 j  1
x
-1,0 0,1 1,1

-1,0 0,0 1,0


Coordinates
-1,-1 0,-1 1,-1
Averages

 Mean
n

I  I In I i
I 1 2  i 1
n n

 Weighted mean
n

w I  w2 I 2    wn I n w I i i
I 11  i 1
n n
Gaussian Filter

 x2 ( x2  y 2

g ( x)  e 2 g ( x, y )  e 2 2
2

g ( x)  .011 .13 .6 1 .6 .13 .011  1


Properties of Gaussian

 Most common natural model


 Smooth function, it has infinite number of
derivatives
 Fourier Transform of Gaussian is Gaussian.
 Convolution of a Gaussian with itself is a
Gaussian.
 There are cells in eye that perform Gaussian
filtering.
Filtering

 Modify pixels based on some function of the


neighborhood

10 30 10
f  p
20 11 20 5.7
11 9 1

Alper Yilmaz, Mubarak Shah, UCF


Linear Filtering

 The output is the linear combination of the


neighborhood pixels

1 3 0 1 0 -1
2 10 2  1 0.1 -1 = 5
4 1 1 1 0 -1
Image Kernel Filter Output

Alper Yilmaz, Mubarak Shah, UCF


Filtering Examples

0 0 0
* 0 1 0 
0 0 0

Alper Yilmaz, Mubarak Shah, UCF


Filtering Examples

0 0 0
* 0 0 1 
0 0 0

Alper Yilmaz, Mubarak Shah, UCF


Filtering Examples

1 1 1
1 
* 1 1 1
9
1 1 1

Alper Yilmaz, Mubarak Shah, UCF


Filtering Examples

1 1 1 1 1
1 1 1 1 1
1 
* 1 1 1 1 1
25
1 1 1 1 1
1 1 1 1 1

Alper Yilmaz, Mubarak Shah, UCF


Blurring Examples

2.4
0.3

original pixel offset filtered

8 8
6
4.8
4 4
0.3

0
original pixel offset filtered
Filtering Gaussian

* 

Alper Yilmaz, Mubarak Shah, UCF


Gaussian vs. Smoothing

Gaussian Smoothing Smoothing by Averaging


Alper Yilmaz, Mubarak Shah, UCF
Noise Filtering

After Averaging

Gaussian Noise

After Gaussian Smoothing


Alper Yilmaz, Mubarak Shah, UCF
MATLAB Functions

 conv: 1-D Convolution.


– C = conv(A, B) convolves vectors A and B.

 conv2: Two dimensional convolution.


– C = conv2(A, B) performs the 2-D convolution
of matrices A and B.
MATLAB Functions

 filter2: Two-dimensional digital filter.


– Y = filter2(B,X) filters the data in X with the 2-D
FIR filter in the matrix B.
– The result, Y, is computed using 2-D correlation and is
the same size as X.
– filter2 uses CONV2 to do most of the work. 2-
D correlation is related to 2-D convolution by a
180 degree rotation of the filter matrix.
MATLAB Functions

 gradient: Approximate gradient.


– [FX,FY] = gradient(F) returns the numerical
gradient of the matrix F. FX corresponds to dF/dx,
FY corresponds to dF/dy.
 mean: Average or mean value.
– For vectors, mean(X) is the mean value
(average) of the elements in X.
MATLAB Functions

 special: Create predefined 2-D filters


– H = fspecial(TYPE) creates a two-dimensional filter H of the
specified type. Possible values for TYPE are:
– 'average' averaging filter;
– 'gaussian' Gaussian lowpass filter
– 'laplacian' filter approximating the 2-D Laplacian operator
– 'log' Laplacian of Gaussian filter
– 'prewitt' Prewitt horizontal edge-emphasizing filter
– 'sobel' Sobel horizontal edge-emphasizing filter
– Example: H=fspecial('gaussian',7,1) creates a 7x7 Gaussian
filter with variance 1.

You might also like