Professional Documents
Culture Documents
Linear System
h(x,y)
g ( x, y ) = f ( x, y ) h( x, y ) =
f ( x , y ) h ( x x , y y )dxdy
E.G.M. Petrakis
Filtering
Impulse Response
Systems output to an impulse (x,y)
(x,y)
I
t
E.G.M. Petrakis
Filtering
Space Invariance
g(x,y) remains the same irrespective of the
position of the input pulse
(x-x0,y-y0)
h(x-x0,y-y0)
E.G.M. Petrakis
LSI System
Filtering
ah1(x,y)+bh2(x,y)
Discrete Convolution
The filtered image is described by a discrete
convolution
g (i, j ) = f (i, j ) h(i, j ) =
n
k =1
l =1
f (k , l )h(i k , j l )
The filter is described by a n x m discrete
convolution mask
E.G.M. Petrakis
Filtering
Computing Convolution
Invert the mask g(i,j) by 180o
not necessary for symmetric masks
E.G.M. Petrakis
Filtering
Image Filtering
Images are often corrupted by random
variations in intensity, illumination, or have
poor contrast and cant be used directly
Filtering: transform pixel intensity values to
reveal certain image characteristics
Enhancement: improves contrast
Smoothing: remove noises
Template matching: detects known patterns
E.G.M. Petrakis
Filtering
Template Matching
Locate the template in the image
E.G.M. Petrakis
Filtering
D ( x, y ) = [ f ( x, y) t ( x x, y y )]
2
x = 0 y = 0
t(x,y): template
M,N size of the template
E.G.M. Petrakis
Filtering
D ( x, y ) =
2
[ f (x, y) t (x x, y y )]
x =1 y =1
M
f (x, y)
background
x =1 y =1
M
t (x x, y y )
x =1 y =1
M
constant
correlation:
convolution of
f(x,y) with t(-x,-y)
2 f ( x, y )t ( x x, y y )
=1 y =1
x
E.G.M. Petrakis
Filtering
template
1 1 1
1 1 1
1 1 1
1 1 0 0 0
1 1 1 0 0
1 0 1 0 0
0 0 0 5 0
0 0 0 0 0
noise
E.G.M. Petrakis
correlation
4
5
3
5
7
5
6
3
3
8
6
false match
Filtering
10
Observations
If the size of f(x,y) is n x n and the size
of the template is m x m the result is
accumulated in a (n-m-1) x (n+m-1) matrix
Best match: maximum value in the
correlation matrix but,
false matches due to noise
E.G.M. Petrakis
Filtering
11
Disadvantages of Correlation
Sensitive to noise
Sensitive to variations in orientation and scale
Sensitive to non-uniform illumination
Normalized Correlation (1:image, 2:template):
(q ) = E (q ) E (q )
E : expected value
E.G.M. Petrakis
Filtering
12
Histogram Modification
Images with poor contrast usually contain
unevenly distributed gray values
Histogram Equalization is a method for
stretching the contrast by uniformly
distributing the gray values
enhances the quality of an image
useful when the image is intended for viewing
not always useful for image processing
E.G.M. Petrakis
Filtering
13
Example
The original image has very poor contrast
the gray values are in a very small range
E.G.M. Petrakis
Filtering
14
Filtering
15
zk z1
z' =
( z a ) + z1
ba
the resulting histogram may have gaps
E.G.M. Petrakis
Filtering
16
Algorithm:
1. Scan the input histogram from left to right to find k1:
k1 1
p
i =1
k1
q1 < pi
i =1
Filtering
17
Algorithm (conted)
2. Scan the input histogram from k1 and to the right to
find k2:
k 2 1
p
i =1
k2
q1 + q2 < pi
i =1
E.G.M. Petrakis
Filtering
18
Noise
Images are corrupted by random variations
in intensity values called noise due to nonperfect camera acquisition or environmental
conditions.
Assumptions:
Additive noise: a random value is added at each
pixel
White noise: The value at a point is
independent on the value at any other point.
E.G.M. Petrakis
Filtering
19
E.G.M. Petrakis
20
a.
b.
c.
d.
e.
Original image
Original image
Salt and pepper noise
Impulse noise
Gaussian noise
E.G.M. Petrakis
Filtering
21
Noise Filtering
Basic Idea: replace each pixel intensity value with
an new value taken over a neighborhood of fixed
size
Mean filter
Median filter
E.G.M. Petrakis
Filtering
22
Mean Filter
Take the average of intensity values in a m x
n region of each pixel (usually m = n)
take the average as the new pixel value
1
h (i, j ) =
f (k , l )
mn km ln
the normalization factor mn preserves the range
of values of the original image
E.G.M. Petrakis
Filtering
23
3 3
1 1 1
simple filter, the same for all types of noise
disadvantage: blurs image, detail is lost
E.G.M. Petrakis
Filtering
24
Size of Filter
The size of the filter controls the amount of
filtering (and blurring).
5 x 5, 7 x 7 etc.
1
1
1
g (i, j) =
1
5 5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Filtering
25
Examples of Smoothing
E.G.M. Petrakis
Filtering
26
Median Filter
E.G.M. Petrakis
Filtering
27
Filtering
28
E.G.M. Petrakis
Filtering
29
Gaussian Filter
Filtering with a m x m mask
the weights are computed according to a
i2 + j2
Gaussian function:
2
g(i, j) = c e 2
is user defined
Example:
m=n=7
2 = 2
E.G.M. Petrakis
1
4
10
7
4
1
4 7 10 7 4
12 26 33 26 12
26 55 71 55 26
33 71 91 71 33
26 55 71 55 26
12 26 33 26 12
4
Filtering
10
1
4
7
10
7
4
1
30
Filtering
31
Gaussian Mask
E.G.M. Petrakis
Filtering
32
Gaussian Smoothing
Filtering
33
Computational Efficiency
Filtering twice with g(x) is equivalent to
filtering with a larger filter with = 2
Assumptions
x2
g ( x, y ) = e
2 2
h ( x, y ) = f ( x, y ) g ( x, y )
h( x, y ) = f ( x, y ) g ( x, y ) g ( x, y )
E.G.M. Petrakis
Filtering
34
g (x ) g (x ) = e
2
2
2
(
x )2
2 2
d =
x
+
+ 2
2 2
x
2
2 2
d =
2 x2
2 +
2
+
2 2
d = e (
2
x2
2
)2
E.G.M. Petrakis
Filtering
35
Observations
Filter an image with a large Gaussian 2
equivalently, filter the image twice with a
Gaussian with small
filtering twice with a m x n Gaussian is
equivalent to filtering with a (n + m - 1) x (n +
m - 1) filter
this implies a significant reduction in
computations
E.G.M. Petrakis
Filtering
36
Gaussian Separability
h (i, j ) = f (i, j ) g (i, j ) =
m
= g (k , l ) f (i k , j l ) =
k =1 l =1
m
= e
(k
+l 2
2 2
f (i k , j l ) =
k =1 l =1
E.G.M. Petrakis
Filtering
37
2
k
l
m
2 n
2
2
2
f (i k , j l ) =
= e
e
k =1
l =1
44424443
1
h'
= e
k2
2
2
h(i k , j )
k =1
The
1-D Gaussian
horizontally
1-D Gaussian
vertically
E.G.M. Petrakis
Filtering
38
Filtering
39
Gaussian Separability
Filtering with a 2D Gaussian can be
implemented using two 1D Gaussian
horizontal filters as follows:
Filtering
40
a. Noisy image
b. Convolution with
1D horizontal
mask
c. Transposition
d. Convolution with
same 1D mask
e. Transposition
smoothed image
E.G.M. Petrakis
Filtering
41