Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Lecture 12: Image Processing and 2D

Transforms
Harvey Rhody
Chester F. Carlson Center for Imaging Science
Rochester Institute of Technology
rhody@cis.rit.edu

October 18, 2005

Abstract
The Fourier transform provides information about the global
frequency-domain characteristics of an image. The Fourier description
can be computed using discrete techniques, which are natural for
digital images. Here we focus on the relationship between the spatial
and frequency domains.

DIP Lecture 12
2D Fourier Transform
Let f (x, y) be a 2D function that may have infinite support. The 2D Fourier
transform pair is defined
Z ∞Z ∞
F(u, v) = f(x, y)e−i2π(ux+vy)dxdy
−∞ −∞
Z ∞ Z ∞
f(x, y) = F(u, v)ei2π(ux+vy)dudv
−∞ −∞
We are interested in transforms related to images, which are defined on a
finite support. If an image has width A and height B with the origin at the
center, then
Z A/2 Z B/2
F(u, v) = f(x, y)e−i2π(ux+vy)dxdy
−A/2 −B/2

where f(x, y) represents the image brightness at point (x, y).


This expression assumes that f(x, y) is extended with f(x, y) = 0 outside
the image frame.

DIP Lecture 12 1
Periodic Extension
If it is assumed that f(x, y) is extended periodically outside the image frame
then we can use a Fourier series.

X ∞
X
f(x, y) = F (u, v)ei2π(ux/A+vy/B)
u=−∞ v=−∞

Note the following:

1. (u, v) take on integer values.


2. (x, y) take on a continuum of values.
3. f(x, y) is periodic with

f(x + nA, y + mB) = f(x, y)

for any integers (n, m).

DIP Lecture 12 2
Fourier Series Coefficient
Multiply both sides of the Fourier series expression by e−i2π(ax/A+by/B)and
integrate over the image frame.
Z A/2 Z B/2
by
−i2π( ax
A +B)
f(x, y)e dxdy
−A/2 −B/2
∞ ∞ Z A/2 Z B/2  x(u−a) y(v−b)

i2π + B
X X
= F (u, v) e A dxdy
u=−∞ v=−∞ −A/2 −B/2

= ABF (a, b)

DIP Lecture 12 3
Fourier Series Coefficient (cont)
Hence, the Fourier series coefficient is
Z A/2 Z B/2
1 −i2π( ax by
F (a, b) = f(x, y)e A +B) dxdy
AB −A/2 −B/2

 
1 a b
= F , for integer (a, b)
AB A B

DIP Lecture 12 4
Bandwidth Limited Approximation
Suppose that F(u, v) ≈ 0 outside a region

Suv = {u, v| − Wu ≤ u ≤ Wu, −Wv ≤ v ≤ Wv }

Then it can be extended periodically outside Suv and expressed as a Fourier


series over the spatial domain.
∞ ∞
X X ux + vy )
−i2π( 2W
F(u, v) = f (x, y)e u 2Wv

x=−∞ y=−∞

Note that:

1. (x, y) take on integer values.


2. (u, v) take on a continuum of values.
3. F(u, v) is periodic with

F(u + 2nWu, v + 2mWv ) = F(u, v) for any integers (n, m)

DIP Lecture 12 5
Fourier Series Coefficient
We can use an analysis similar to the above to find the value of f (s, t) at
integer values of (s, t). We find
 
1 s t
f (s, t) = f ,
4WuWv 2Wu 2Wv
 
1 1
The image plane is sampled on a grid with spacing 2W ,
u 2Wv
. The
number of samples that are needed in each dimension are

N = 2AWu
M = 2BWv

DIP Lecture 12 6
Discrete Fourier Transform
We have already seen that
 
1 a b
F (a, b) = F ,
AB A B

All of the information we need is provided by samples of F(u, v) on a grid


with spacing A1 , B1 . The number of points need are


N = 2AWu
M = 2BWv

We need the same number of values to describe the image, whether the
values are from the spatial domain or the frequency domain.

The samples of F are complex numbers, but the information is the same
because of symmetries.

DIP Lecture 12 7
Discrete Fourier Transform
We can now construct the DFT pair by substituting into

∞ ∞
X X ux + vy )
−i2π( 2W
F(u, v) = f (x, y)e u 2Wv

x=−∞ y=−∞

  N −1 M −1  
a b X X 1 x y −i2π ax by
2AWu + 2BWv
ABF (a, b) = F , = f( , )e
A B x=0 y=0
4WuWv 2Wu 2Wv

N −1 M −1  
1 X X x y ax by
−i2π N + M
F (a, b) = f( , )e
M N x=0 y=0 2Wu 2Wv

DIP Lecture 12 8
Discrete Fourier Transform
It is conventional to replace f with f without keeping track of the extra
4WuWv factor. We’ll follow convention and worry about the scaling when
we do numerical computations. We’ll also replace (a, b) by (u, v). This
produces the transform pair

N −1 M −1
1 X X −i2π ( ux vy
F (u, v) = f (x, y)e N + M)
M N x=0 y=0

N −1 M −1
vy
i2π ( ux
N +M )
X X
f (x, y) = F (u, v)e
u=0 v=0
It is often the case that the origin of an array that represents F (u, v) is at a
corner. This does no harm because F (u, v) is periodic with period (N, M ),
but one must pay attention.

DIP Lecture 12 9
Example: G&W Figure 4.3

40 × 20 Rectangle |F (u, v)| Row and Column Profiles

DIP Lecture 12 10
Example: G&W Figure 4.6

Original Spectrum

Image with F (0, 0) = 0 Spectrum contours

DIP Lecture 12 11
Fourier Image Components
An image, represented by f (x, y) is the sum of a set of component images

vy
i2π ( ux + M)
f (x, y; u, v) = F (u, v)e N

We can write the image as

N
X −1 M
X −1
f (x, y) = f (x, y; u, v)
u=0 v=0

It is important to understand the nature of the image components.

DIP Lecture 12 12
What is f (x, y; u, v)?

1. F (u, v) is just a complex number. There are M N of them–one for each


(u, v) combination.

2. F (u, v) = A(u, v)eiθ(u,v) where A(u, v) is the size and θ(u, v) is the
angle of the complex number.

3. It is a compact way to write

vy
i2π ( ux
N +M )
f (x, y; u, v) = F (u, v)e
h  ux
vy  i
= A(u, v) cos 2π + + θ(u, v)
N M
h  ux vy  i
+ iA(u, v) sin 2π + + θ(u, v)
N M

DIP Lecture 12 13
vy
i2π ( ux
N M)
+
What is F (u, v)e ?
4. If f (x, y) is real then F (u, v)=F ∗(N − u, M − v). This means that
A(N − u, M − v) = A(u, v) and θ(N − u, M − v) = −θ(u, v).

5. We can combine the (u, v) and (N − u, M − v) terms as


 (N −u)x (M −v)y

vy
i2π ux
(
N +M ) + F (N − u, M − v)ei2π N + M
F (u, v)e
h  ux vy  i
= 2A(u, v) cos 2π + + θ(u, v)
N M

6. Similarly, for real f (x, y), the (u, M − v) and (N − u, v) terms can be
combined since F (u, M − v) = F ∗(N − u, v)
 (M −v)y
  (N −u)x 
i2π ux
N+ i2π + vy
F (u, M − v)e M + F (N − u, v)e N M

h  ux vy  i
= 2A(u, M − v) cos 2π − + θ(u, M − v)
N M

DIP Lecture 12 14
The long version

N/2−1
X h ux i
f (x, y) = A[0, 0] + 2A(u, 0) cos 2π + θ(u, 0)
u=1
N
M/2−1
X h vy i
+ 2A(0, v) cos 2π + θ(0, v)
v=1
M
N/2−1 M/2−1  ux
X X h vy  i
+ 2A(u, v) cos 2π + + θ(u, v)
u=1 v=1
N M
N/2−1 M/2−1  ux
X X h vy  i
+ 2A(u, M − v) cos 2π − + θ(u, M − v)
u=1 v=1
N M

Examples of some of the components are shown on the next slide.

DIP Lecture 12 15
Some Components

u=1v=0 u=0v=1 u=1v=2

u = 2 v = −1 u=3v=5 u=5v=3

DIP Lecture 12 16
Filtering
Let H(u, v) be the system function of a linear shift-invariant filter.
Let f (x, y) be the input image and g(x, y) be the output image.
The LSI filter operates independently on each of the exponential function
image components.
yv
i2π ( xu
N +M )
f (x, y; u, v) = F (u, v)e

The corresponding component of the output image is

g(x, y; u, v) = H(u, v)f (x, y; u, v)


yv
i2π ( xu
N +M )
= H(u, v)F (u, v)e

The complete output image is

N
X −1 M
X −1
g(x, y) = g(x, y; u, v)
u=0 v=0

DIP Lecture 12 17
Filtering
The output image g(x, y) has a DFT

N −1 M −1
1 X X −i2π ( ux + vy
G(u, v) = g(x, y)e N M)
M N x=0 y=0

N −1 M −1
vy
i2π ( ux
N +M )
X X
g(x, y) = G(u, v)e
u=0 v=0
where
G(u, v) = H(u, v)F (u, v)

The filter operates by changing the magnitude and phase of each (u, v)
component by multiplying F (u, v) by H(u, v).

DIP Lecture 12 18
Filter Construction
An image can be processed by multiplication with a filter function

G(u, v) = F (u, v)H(u, v)

Butterworth lowpass filter:

1
H(u, v) =  n
u2 +v 2
1+ D02

Butterworth filter of order n = 2

DIP Lecture 12 19
Constructing a Filter Array
Given an image of size N × M , we need to construct a filter of the same
size. For a Butterworth LP of order p do the following:

x=Indgen(N)-N/2 ;x-axis (centered)


y=Indgen(M)-M/2 ;y-axis (centered
u=x#replicate(1,M) ;The u-coordinate plane
v=y##replicate(1,N) ;The v-coordinate plane
D=(u^2+v^2)/D0^2
H=1/(1+D^p)
surface,H,u,v

DIP Lecture 12 20
Filtering with LPF

Original After LPF

Spectrum |HLP (u, v)|

DIP Lecture 12 21
HPF Characteristic
A highpass filter can be constructed from a lowpass filter by subtraction.

HHP (u, v) = HLP (0, 0) − HLP (u, v)

For the Butterworth filter

1
HHP (u, v) = 1 −  n
u2 +v 2
1+ D02

 2 2
n
u +v
D02
=  n
u2 +v 2
1+ D02

DIP Lecture 12 22
Filtering with HPF

Original After HPF

Spectrum |HHP (u, v)|

DIP Lecture 12 23
Filter Construction
;Construct coordinate arrays of size NxM
u=(Findgen(N)-N/2)#Replicate(1,M)
v=(Findgen(M)-M/2)##Replicate(1,N)
;Construct a lowpass filter
D0=30
LPF=(u^2+v^2) LT D0^2
;Show the filter response function
Window,/free,xsize=300,ysize=300
Shade Surf,LPF,u,v

DIP Lecture 12 24
Image Filtering
A=Read Image(‘restest.jpg’)
Sa=Size(A,/dimensions)
N=Sa[0] & M=Sa[1]
Window,/free,xsize=N,ysize=M
TV,A
AF=FFT(A)
AFS=Shift(AF,N/2,M/2)
AFSH=LPF*AFS
A2=Abs(FFT(AFSH,/Inverse))
Window,/free,xsize=N,ysize=M
TVSCL,A2

DIP Lecture 12 25

You might also like