lecture7_LinearFilters
lecture7_LinearFilters
Rutgers University
Spring 2004
Ahmed Elgammal
Dept of Computer Science
Rutgers University
Outlines
• What are linear filters
• Smoothing and convolution
• Image noise
• Smoothing with a Gaussian
• Differentiation and convolution
• Fourier Transform, Discrete Fourier Transform
• Sampling and Aliasing
1
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
Digital image
• Assume we use a gray-level image
• Digital image: a two-dimensional light intensity function
f(x,y) where x and y denote spatial coordinates, the value
of f at any point is proportional to the brightness (gray
level) of the image at that point.
• A digital image:
– is discretized in the spatial domain
– Is discretized in the brightness domain. f(x,y)
Linear Filters
General process:
• Form new image whose pixels are a weighted sum of original pixel
values, using the same set of weights at each point.
Properties
• Output is a linear function of the input
• Output is a shift-invariant function of the input (i.e. shift the input
image two pixels to the left, the output is shifted two pixels to the left)
• This operation is called convolution
weights
2
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
n
h(i) = ∑ g( j) f (i + j)
j =− n
1 2 3 4 5 6
f 8 7 8 22 23 12 10 11 9 5 6 4
g 1/13 1 3 5 3 1
n
∑ g( j) f (i + j)
1 3 5 3 1
1 3 5 3 1
h(i) =
j =− n
h 12 17 18
2
h(4) = ∑ g( j) f ( 4 + j)
j =−2
3
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
• Convolution computes the weighted sum of the gray levels in each nxn
neighborhood of the image, f, using the matrix of weights g.
• Convolution is a so-called linear operator because
– g*(af1 + bf 2) = a(g*f 1) + b(g*f 2)
• Convolution is shift invariant.
2-D convolution
1 1
h(5,5) = ∑ ∑ g (k,l) f (5 + k,5 + l)
k = −1l = −1
4
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
5
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
An Isotropic Gaussian
• The picture shows a smoothing
kernel proportional to
x2 + y2
exp −
2σ 2
6
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
Gaussian smoothing
• Advantages of Gaussian filtering
– rotationally symmetric (for large filters)
– filter weights decrease monotonically from central peak, giving
most weight to central pixels
– Simple and intuitive relationship between size of σ and the
smoothing.
– The Gaussian is separable:
(x2 +y2) x2 y2
− 2 − 2 − 2
e 2σ =e 2σ ∗e 2σ
7
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
Advantage of seperability
• First convolve the image with a one dimensional horizontal
filter
• Then convolve the result of the first convolution with a one
dimensional vertical filter
• For a kxk Gaussian filter, 2D convolution requires k2
operations per pixel
• But using the separable filters, we reduce this to 2k
operations per pixel.
Separability
2 3 3 11
1 2 1 3 5 5 18
4 4 6 18
1 11
2 18 65
1 18
1 x 1 2 1 1 2 1 2 3 3 =2 + 6 + 3 = 11
2 = 2 4 2 3 5 5 = 6 + 20 + 10 = 36
1 1 2 1 4 4 6 = 4 + 8 + 6 = 18
65
CS 534 – Ahmed Elgammal 16
8
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
Advantages of Gaussians
• Convolution of a Gaussian with itself is another Gaussian
– so we can first smooth an image with a small Gaussian
– then, we convolve that smoothed image with another small
Gaussian and the result is equivalent to smoother the original
image with a larger Gaussian.
– If we smooth an image with a Gaussian having sd σ twice, then we
get the same result as smoothing the image with a Gaussian
having standard deviation (2σ)1/2
Noise
• Simplest noise model
– independent stationary additive Gaussian noise
– the noise value at each pixel is given by an independent draw from
the same normal probability distribution
fobserved ( x, y) = f ( x, y) + N (0, σ 2 )
• Issues
– this model allows noise values that could be greater than maximum
camera output or less than zero
– for small standard deviations, this isn’t too much of a problem - it’s
a fairly good model
– independence may not be justified (e.g. damage to lens)
– may not be stationary (e.g. thermal gradients in the ccd)
9
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
sigma=1
sigma=16
10
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
u,v
N ′( 0, σ ′2 )
CS 534 – Ahmed Elgammal 21
11
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
∂f f (x + ε, y) f (x, y )
= lim −
∂x ε→ 0 ε ε
• Now this is linear and shift invariant, so must be the result of a
convolution.
• We could approximate this as 0 0 0
∂f f (xn+1 , y )− f (xn , y) G = 1 0 − 1
≈ 0 0 0
∂x ∆x
(which is obviously a convolution; it’s not a very good way to do things, as
we shall see)
Finite differences
12
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
13
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
Fourier Transform
• Fourier Transform as a change of basis
∞
− j 2πux
F (u ) = ∫ f ( x) e
−∞
dx
e − j 2πux = cos(2πux ) − j sin( 2πux)
∞
j 2πux
f ( x) = ∫ F (u ) e
−∞
du
FT
F ( u) = R(u) + jI (u)
φ (u ) = tan −1 I (u ) / R (u )
f(x) |F(u)|2
Power Spectrum
Lower frequencies ⇒ narrower power spectrum
x u
14
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
Important Properties:
• Fourier transform is linear
F ( g ( x ) + h( x )) = F ( g( x )) + F (h( x ))
F (kg ( x )) = k F ( g ( x ))
• FT and Convolution
f ( x) ∗ g ( x ) ⇔ F ( u)G ( u)
f ( x ) g ( x ) ⇔ F ( u ) ∗ G ( u)
• FT of a Gaussian is a Gaussian
x =0
N −1
∑ F (u ) e
− j 2π ux / N
f ( x) =
u =0
• Important Property:
Periodicity F(u)=F(u+N)
One period
CS 534 – Ahmed Elgammal 30
15
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
2-dimension
∞
In two dimension − j 2π ( ux + vy)
F (u , v ) = ∫ ∫ f ( x, y ) e dxdy
−∞
∞
j 2 π ( ux+ vy)
f ( x, y ) = ∫ ∫ F (u, v ) e dudv
−∞
− j 2π ( ux + vy)
e = cos(2π (ux + vy )) + j sin( 2π (ux + vy ))
• These terms are sinusoids on the x,y plane whose
orientation and frequency are defined by u,v
FT
16
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
17
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
18
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
unsuccessful sampling
CS 534 – Ahmed Elgammal 37
19
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
Aliasing
• Nyquist theorem: The
sampling frequency must
be at least twice the highest
frequency present for a
signal to be reconstructed
from a sampled version.
(Nyquist frequency)
20
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
21
CS 534 Spring 2003: Ahmed Elgammal,
Rutgers University
Sources
• Forsyth and Ponce, Computer Vision a Modern approach:
chapter 7.
• R. Gonzalez and P. Wintz, Digital Image Processing,
second edition.
• Slides by:
– D. Forsyth
• Fourier transform images from Prof. John M. Brayer @
UNM
http://www.cs.unm.edu/~brayer/vision/fourier.html
• Aliasing java applets available at
http://klebanov.homeip.net/~pavel/fb/java/la_applets/Aliasing/
http://www.dsptutor.freeuk.com/aliasing/AliasingDemo.html
22