Fourier Transform 2D
Discrete Fourier Transform - 2D Continues Fourier Transform - 2D Fourier Properties Convolution Theorem Examples
+ + +
Definitions
Spatial Domain (I)
Normal image space Changes in pixel positions correspond to changes in the scene Distances in I correspond to real distances
Frequency Domain (F)
Changes in image position correspond to changes in the spatial frequency This is the rate at which image intensity values are changing in the spatial domain image I
Image Processing
Spatial Domain (I)
Directly process the input image pixel array
Frequency Domain (F)
Transform the image to its frequency representation Perform image processing Compute inverse transform back to the spatial domain
Frequencies in an Image
Any spatial or temporal signal has an equivalent frequency representation What do frequencies mean in an image ?
High frequencies correspond to pixel values that change rapidly across the image (e.g. text, texture, leaves, etc.) Strong low frequency components correspond to large scale features in the image (e.g. a single, homogenous object that dominates the image)
We will investigate Fourier transformations to obtain frequency representations of an image
The Fourier Series
Periodic functions can be expressed as the sum of sines and/or cosines of different frequencies each multiplied by a different coefficient
The Fourier Transform
Functions that are NOT periodic BUT with finite area under the curve can be expressed as the integral of sines and/or cosines multiplied by a weight function
Fourier Transform
F (u ) =
Fourier Synthesis
f ( x )e
j 2ux
dx
Fourier Analysis
f ( x) =
F (u )e
j 2ux
du
Inverse Fourier Transform
The Fourier Transform
The FT transforms can be easily extended to 2 (and n dimensions)
F (u, v) =
f ( x, y )e F (u, v)e
j 2 ( ux + vy )
dxdy
f ( x, y ) =
j 2 ( ux + vy )
dudv
The Fourier transform for f(x) exists iff
1. 2. f(x) is piecewise continuous on every finite interval f(x) is absolutely integrable
Properties of the Fourier Transform
The FT is a linear operator
F (af + bg ) = aF ( f ) + bF ( g )
Some other useful properties include Discrete Real f+g f*g Periodic Symmetric F+G FG
Some Fundamental Transform Pairs
Box Sinc
F (u ) =
j 2xu dx f ( x )e j 2xu dx = e 1
1 j 2u j 2u e e j 2u sin 2u = u =
The 2D Discrete Fourier Transform
For an image f(x,y) x=0..N-1, y=0..M-1, there are two-indices basis functions Bu.v(x,y):
1 Bu,v (x, y ) = e MN
ux v y 2 i + N M
u=0..N-1, M=0..M-1
The inner product of 2 functions (in 2D) is defined similarly to the 1D case :
F (u , v ) = f (x , y ), B u , v (x , y ) = =
N 1 M 1 x =0 y =0
* f (x , y )B u , v (x , y )
u=-2, v=2
u=-1, v=2
u=0, v=2
u=1, v=2
u=2, v=2
u=-2, v=1
u=-1, v=1
u=0, v=1
u=1, v=1
u=2, v=1
U
u=-2, v=0 u=-1, v=0 u=0, v=0 u=1, v=0 u=2, v=0
u=-2, v=-1
u=-1, v=-1
u=0, v=-1
u=1, v=-1
u=2, v=-1
u=-2, v=-2
u=-1, v=-2
u=0, v=-2
u=1, v=-2
u=2, v=-2
Aliasing Examples
75 dpi Scan
600 dpi Scan
How might we handle this effect? Moire Pattern
* Wikipedia
DFT (Continued)
Since the values of the FT are complex numbers, it is sometimes more convenient to express F(u) in terms of polar coordinates
F (u , v ) = F (u , v ) e j ( u , v )
where the magnitude or spectrum is denoted by
F (u , v ) = R 2 (u , v ) + I 2 (u, v)
1 2
and the phase angle by
(u, v) = tan 1
I (u , v) R (u , v)
11
DFT (Continued)
F (u , v) =
1 MN
M 1 N 1 x =0 y = 0
f ( x, y)e
j 2 ( ux / M + vy / N )
At u=v=0, the FDT reduces to
F (0,0) = 1 MN
M 1 N 1 x =0 y =0
f ( x, y)
This is nothing more than the average grayscale level of the image This is often referred to as the DC Component (0 frequency)
DFT (Continued)
The FT has the following translation property
f ( x, y )e j 2 (u0 x / M +v0 y / N ) F (u u0 , v v0 )
which for u0=M/2 and v0=N/2 we see that
e j 2 (ux / M +vy / N ) = e j ( x + y ) = (1) x + y
F ( f ( x, y )(1) x + y ) = F (u M / 2, v N / 2)
In image processing, it is common to multiply the input image by (-1)x+y prior to computing F(u,v) This has the effect of centering the transform since F(0,0) is now located at u=M/2, v=N/2
12
The Discrete Fourier Transform (DFT)
F(k) = f ( x),e
2 ikx N
= f (x) e
x =0
N1
2ikx N
k = 0, 1, 2, ..., N-1
Matlab: F=fft(f);
The Inverse Discrete Fourier Transform (IDFT) is defined as:
1 f ( x) = N
N 1 k =0
F (k ) e
2ikx N
x = 0, 1, 2, ..., N-1
Matlab: F=ifft(f);
Remark: Normalization constant might be different!
16
Discrete Fourier Transform - Example
f(x) = [2 3 4 4]
F(0) = =
x=0
f(x) e
-2i0x
4
x=0
f(x) 1
(f(0) + f(1) + f(2) + f(3)) = (2+3+4+4) = 13
F(1) =
f(x) e x=0
3
-2ix
4
[2e0+3e-i/2+4ei+4e-i3/2] = [-2+i]
F(2) =
f(x) e x=0 f(x) e x=0
3
-4ix
4
= [2e0+3e-i+4e2i+4e-3i] = [-1-0i]= -1
F(3) =
-6ix
4
= [2e0+3e-i3/2+4e3i+4e-i9/2] = [-2-i]
DFT of [2 3 4 4] is
[ 13 (-2+i) -1 (-2-i) ]
17
Sampling Limits
Shannons Sampling Theorem states that if a function f is sampled at a rate twice its highest frequency, f can be completely recovered from its samples This is known as the Nyquist Frequency Limit The sampling rate in images is the pixels/unit distance
er
Aliasing
For an image sampled spatially, the shortest wavelength that be represented is 2 pixels When a signal is under-sampled, aliasing can result Aliasing is when a high frequency signal masquerades as a lower frequency signal
10
Sampling
When we sample, we lose information When is sampling adequate? Consider sampling of a checkerboard image Top row: 2 and one samples per feature Will that be enough? Bottom row
Sampling
Sampling and the Nyquist rate
Aliasing can arise when you sample a continuous signal or image
Demo applet
http://www.cs.brown.edu/exploratories/freeSoftware/repository/edu/brown/cs/exploratories/app lets/nyquist/nyquist_limit_java_plugin.html
occurs when your sampling rate is not high enough to capture the amount of detail in your image formally, the image contains structure at different scales
called frequencies in the Fourier domain
the sampling rate must be high enough to capture the highest frequency in the image
To avoid aliasing:
sampling rate > 2 * max frequency in the image
i.e., need more than two samples per period
This minimum sampling rate is called the Nyquist rate
Visualizing the Fourier Transform Image using Matlab Routines
F(u,v) is a Fourier transform of f(x,y) and it has complex entries.
F = fft2(f);
In order to display the Fourier Spectrum |F(u,v)| Reduce dynamic range of |F(u,v)| by displaying the log:
D = log(1+abs(F));
Cyclically rotate the image so that F(0,0) is in the center:
Example:
D = fftshift(D);
2 1 0 0 1 2 4
|F(u)| = 100 4
Display in Range([0..10]): log(1+|F(u)|) = 4.62 1.61 1.01 0.69 0 0 0.69 1.01 1.61 log(1+|F(u)|)/0.0462 = 10 4 2 1 0 fftshift(log(1+|F(u)|) = 0 1 2 4 2 1 0
6
0 1 2 4 10 4
Visualizing the Fourier Image - Example
Original
|F(u,v)|
log(1 + |F(u,v)|)
fftshift(log(1 + |F(u,v)|))
Original
Fourier Image = |F(u,v)|
Shifted Fourier Image
Shifted Log Fourier Image = log(1+ |F(u,v)|)
Example - Rotation
2D Image 2D Image - Rotated
Fourier Spectrum
Fourier Spectrum
17
Fourier Transform Examples
Image Domain Frequency Domain
18
Fourier Transform Examples
Image Domain Frequency Domain
19
Fourier Transform Examples
Image Domain Frequency Domain
20
Fourier Transform Examples
Image Domain Frequency Domain
21
Why do we need representation in the frequency domain?
Problem in Frequency Space
Relatively easy solution
Solution in Frequency Space
Fourier Transform
Inverse Fourier Transform
Original Problem
Difficult solution
Solution of Original Problem
22
Procedure for Filtering in the Frequency Domain
1. 2. 3. 4. 5. 6. Multiply the input image by (-1)x+y to center the transform Compute the DFT F(u,v) of the resulting image Multiply F(u,v) by a filter G(u,v) Computer the inverse DFT transform h*(x,y) Obtain the real part h(x,y) of 4 Multiply the result by (-1)x+y
Filtering Example Smooth an Image with a Gaussian Kernel Traditionally, we would just convolve the image with the a gaussian kernel
1 4 6 4 1 4 16 24 16 4 6 24 36 24 6 / 256 4 16 24 16 4 1 4 6 4 1
Instead, we will perform multiplication in the frequency domain to achieve the same effect
15
Filtering Example Smooth an Image with a Gaussian Kernel 1. Multiply the input image by (-1)x+y to center the transform
Filtering Example Smooth an Image with a Gaussian Kernel 2. Compute the DFT F(u,v) of the resulting image
log transform
16
Filtering Example Smooth an Image with a Gaussian Kernel 3. Multiply F(u,v) by a filter G(u,v)
1 4 6 4 1 4 16 24 16 4 6 24 36 24 6 / 256 4 16 24 16 4 1 4 6 4 1
g(x,y) G(u,v)
Filtering Example Smooth an Image with a Gaussian Kernel 3. Multiply F(u,v) by a filter G(u,v)
17
Filtering Example Smooth an Image with a Gaussian Kernel 4. 5. 6. Computer the inverse DFT transform h*(x,y) Obtain the real part h(x,y) of 4 Multiply the result by (-1)x+y
Filtering Example Smooth an Image with a Gaussian Kernel
f ( x, y ) g ( x, y )
F (u , v)G (u , v)
18
Low pass Filter
spatial domain frequency domain
f(x,y)
F(u,v) G(u,v) = F(u,v) H(u,v)
filter
g(x,y)
G(u,v)
f(x,y)
F(u,v)
g(x,y)
H(u,v)
14
H(u,v) - Ideal Low Pass Filter
H(u,v) =
1 0
D(u,v) D0 D(u,v) > D0
D(u,v) = u2 + v2 D0 = cut off frequency
H(u,v) H(u,v) v u 1 0 D0
D(u,v)
15
Blurring - Ideal Low pass Filter
99.7%
99.37%
98.65%
16
Blurring - Ideal Low pass Filter
96.6%
98.0%
99.0%
99.4%
99.6%
99.7%
17
H(u,v) - Gaussian Filter
H(u,v)
H(u,v) 1
1/ e
u v 0 D0
D(u,v)
H(u,v) =
-D2(u,v)/(2D20)
D(u,v) = u2 + v2
Softer Blurring
20
Blurring - Gaussain Lowpass Filter
99.11%
98.74%
96.44%
The Gaussian Lowpass Filter
Freq. domain
Spatial domain
300 250 200 150 100 50 0
50
100
150
200
250
300
22
H(u,v) - Butterworth Filter
H(u,v)
H(u,v) 1 0.5 v
D0
D(u,v)
H(u,v) =
1 1 + (D(u,v)/D0)2n
D(u,v) = u2 + v2
23
Blurring - Butterworth Lowpass Filter
97.48%
95.95%
93.70%
24
The Butterworth Lowpass Filter
Freq. domain
Spatial domain
250
200
150
100
50
50
100
150
200
250
25
Low Pass Filters - Comparison Ideal Butterworth Gaussian
D0=1 D0=2 D0=3
26
Low Pass Filtering - Image Smoothing
Original - 4 level Quantized Image Smoothed Image
Original Noisy Image
Smoothed Image
28
Image Sharpening - High Pass Filter
H(u,v) - Ideal Filter
H(u,v) = 0 1 D(u,v) D0 D(u,v) > D0
D(u,v) = u2 + v2 D0 = cut off frequency
H(u,v)
H(u,v) v 1 0 D0 D(u,v)
29
H(u,v) - Gaussian High Pass Filter
H(u,v) H(u,v) 1 v u
11/ e
0 D0 D(u,v)
H(u,v) = 1 - e
-D2(u,v)/(2D20)
D(u,v) = u2 + v2
30
H(u,v) - Butterworth High Pass Filter
H(u,v) H(u,v) 1 v u 0.5 0 D0
D(u,v)
H(u,v) =
1 1 + (D0/D(u,v))2n
D(u,v) = u2 + v2
31
High Pass Filters - Comparison Ideal
Butterworth
Gaussian
32
High Pass Filtering
Original
High Pass Filtered
33
High Frequency Emphasis
Original
High Pass Filtered
34
High Frequency Emphasis
Emphasize High Frequency. Maintain Low frequencies and Mean. H'(u,v) = K0 + H(u,v)
(Typically K0 =1)
H'(u,v) 1 0 D0 D(u,v)
35
High Frequency Emphasis - Example
Original High Frequency Emphasis
Original
High Frequency Emphasis
36
High Pass Filtering - Examples
Original High pass Butterworth Filter
High Frequency Emphasis
High Frequency Emphasis + Histogram Equalization
37
Band Pass Filtering
0 H(u,v) = 1 0 D(u,v) D0 D0w
2
w
2
D(u,v) D0 +
w
2
w
2
D(u,v) > D0 +
D(u,v) = u2 + v2 D0 = cut off frequency w = band width
H(u,v)
H(u,v)
v u
1
D(u,v)
D0- w
2
D0 D0+w
2
38
Band Reject Filtering
0 H(u,v) = 1 0 D(u,v) D0 D0w
2
w
2
D(u,v) D0 +
w
2
w
2
D(u,v) > D0 +
D(u,v) = u2 + v2 D0 = cut off frequency w = band width
H(u,v)
H(u,v)
v u
1
D(u,v)
D0- w
2
D0 D0+w
2
39