Chapter 4 Image Enhancement in the Frequency Domain Chapter 4 Image Enhancement in the Frequency Domain An periodic signals can be Fourier series: Any periodic signals can be viewed as weighted sum of sinusoidal signals with of sinusoidal signals with different frequencies Frequency Domain: Frequency Domain: view frequency as an independent variable independent variable
139
Embed
Chapter 4 Image Enhancement in the Frequency Domainjan/204584/04-image_enhancement_freq.pdf · Chapter 4 Image Enhancement in the Frequency Domain An periodic signals can be Fourier
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Chapter 4Image Enhancement in the Frequency Domain
Chapter 4Image Enhancement in the Frequency Domain
An periodic signals can beFourier series:
Any periodic signals can beviewed as weighted sumof sinusoidal signals withof sinusoidal signals with different frequencies
Frequency Domain:Frequency Domain: view frequency as an independent variableindependent variable
Chapter 4Image Enhancement in the Frequency Domain
Chapter 4Image Enhancement in the Frequency DomainImage Enhancement in the Frequency DomainImage Enhancement in the Frequency Domain
Background- From the observation: any periodic function may be written as the sum of sines and consines of varying amplitudes and frequencies
xxf sin)( = xxf sin)(1 =
xxf 3sin31)(2 =
xxf 5sin1)(3 =f5
)(3
xxxxxf 7sin715sin
513sin
31sin)( +++= xxf 7sin
71)(4 =
Chapter 4Image Enhancement in the Frequency Domain
Chapter 4Image Enhancement in the Frequency DomainImage Enhancement in the Frequency DomainImage Enhancement in the Frequency Domain
The more terms of the series we have, the closer of the sum will approach the original function
If f(x) is a function period 2T, then we can writethen we can write
)sincos()(1
0 ++= ∑∞
= Txnb
Txnaaxf
nnn
ππ
)(21
0 = ∫ dxxfT
a
whereT
T
....3,2,1,cos)(1
)(20
== ∫
∫
−
−
ndxT
xnxfT
a
fT
T
Tn
T
π
111
....3,2,1,sin)(1== ∫−
ndxT
xnxfT
bT
Tnπ
xxxxxf 7sin715sin
513sin
31sin)( +++=
Chapter 4Image Enhancement in the Frequency Domain
Chapter 4Image Enhancement in the Frequency DomainImage Enhancement in the Frequency DomainImage Enhancement in the Frequency Domain
)sincos()( 0 ++= ∑∞
Txnb
Txnaaxf nn
ππThe Fourier series expansion of f(x) can
)(1
1
∫
=
df
whereTT
T
nbe expressed in complex form
∑∞
= n dxT
xincxf ,)exp()( π
....3,2,1,cos)(1
)(20
==
=
∫
∫−
ndxxnxfa
dxxfT
a
T
n
T
π∫
∑−∞=
−T
n
dxinf
whereT
)()(1 π
....3,2,1,sin)(1
....3,,,cos)(
== ∫
∫
−
−
ndxT
xnxfT
b
ndxT
xfT
a
T
Tn
Tn
πIf the function is non-periodic, we need
ll f i
∫−=
Tn dxT
xfT
c )exp()(2
TTall frequencies to represent.
[ ]∫∞
∞−+=
h
dxjbxaxf ωωωωω sin)(cos)()(
∫∞
∞−= xdxxfa
where
ωπ
ω ,cos)(1)(θθθ sincos je j +=
∫∞
∞−= xdxxfb ω
πω
π
sin)(1)(
Chapter 4Image Enhancement in the Frequency Domain
Chapter 4Image Enhancement in the Frequency Domain
Ti ti l FFourier Tr.
Time, spatial Domain Signals
Frequency Domain SignalsInv Fourier TrSignals SignalsInv Fourier Tr.
1-D, Continuous case
∫∞
j2∫∞−
−= dxexfuF uxj π2)()(Fourier Tr.:
∞
∫∞
∞
= dueuFxf uxj π2)()(Inv. Fourier Tr.:∞−
Chapter 4Image Enhancement in the Frequency Domain
Chapter 4Image Enhancement in the Frequency Domain
1-D, Discrete casef 1 1 1 1 1 1 1 1
,
fffff = ][
f=1,1,1,1,-1,-1,-1,-1
FFFFF
fffff N −= 1210
][
],....,,[
whereFFFFF N −
⎤⎡
= 1210 ],....,,[
fxNxui
NF
N
xu ∑
−
=⎥⎦⎤
⎢⎣⎡−=
1
02exp1 π
Chapter 4Image Enhancement in the Frequency Domain
Chapter 4Image Enhancement in the Frequency Domain
1-D, Discrete case,
∑−
−=1
/2)(1)(N
NuxjexfuF πFourier Tr : u = 0,…,N-1∑=
=0
)()(x
exfN
uFFourier Tr.:
−1N
Inv. Fourier Tr.: ∑=
=0
/2)()(u
NuxjeuFxf π x = 0,…,N-1
Chapter 4Image Enhancement in the Frequency DomainImage Enhancement in the Frequency Domain
1-D, Discrete caseSuppose
Nx fffff −= 1210 ],....,,[is a sequence of length N. we define DFT to be the sequence
Nu FFFFF −= 1210 ],....,,[ℑfF
N
fxuiF
where
∑−
⎥⎤
⎢⎡1
2exp1 π ⎤⎡
ℑ=where
fF
xx
u fN
iN
F ∑=
⎥⎦⎢⎣−=
0
2exp π⎥⎦⎤
⎢⎣⎡−=ℑ 2exp1
, Nmni
Nnm π
As a matrix multiplication: ⎟⎠⎞
⎜⎝⎛ −+−=ℑ )2sin()2cos(1
, Nmnii
Nmni
Nnm ππ
1-D Discrete Fourier Transforms
1 D Discrete case S f [1 2 3 4] th t N 41-D, Discrete case
Chapter 4Image Enhancement in the Frequency Domain
Chapter 4Image Enhancement in the Frequency Domain
Sines and Consines have variousFrom Euler’s formular
sincos jj θθθ +
Sines and Consines have various frequencies, The domain (u) calledfrequency domain
)]/2sin()/2)[cos((1)(
sincos1
NuxjNuxxfuF
jeM
j
ππ
θθθ +=
∑−
f q y
F( ) b i
)]/2sin()/2)[cos(()(0
NuxjNuxxfN
uFx
ππ −= ∑=
F(u) can be written as)()()( ujeuFuF φ−=or)()()( ujIuRuF += )()(or)()()( j
22
where
⎟⎟⎞
⎜⎜⎛− )(tan)( 1 uIuφ22 )()()( uIuRuF += ⎟⎟
⎠⎜⎜⎝
=)(
tan)(uR
uφ
Chapter 4Example of 1 D Fourier Transforms
Chapter 4Example of 1 D Fourier Transforms Example of 1-D Fourier Transforms Example of 1-D Fourier Transforms
Notice that the longerNotice that the longerthe time domain signal,The shorter its Fouriertransform
(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.
Chapter 4Relation Between Δx and Δu
Chapter 4Relation Between Δx and Δu
F i l f( ) ith N i t l t ti l l ti Δx bFor a signal f(x) with N points, let spatial resolution Δx be space between samples in f(x) and let frequency resolution Δu be space between frequencies components in F(u) we havebetween frequencies components in F(u), we have
u =Δ1)()( 0 xxxfxf Δ+=
Δ
For x = 0,1,2,... N-1
xNu
Δ=Δ
E l f i l f( ) ith li i d 0 5 100 i t)()( uuFuF Δ=
Δ
u = 0,1,2,…N-1Example: for a signal f(x) with sampling period 0.5 sec, 100 point, we will get frequency resolution equal to
1 Hz02.05.0100
1=
×=Δu
This means that in F(u) we can distinguish 2 frequencies that areThis means that in F(u) we can distinguish 2 frequencies that are apart by 0.02 Hertz or more.
Chapter 42-Dimensional Discrete Fourier Transform
Chapter 42-Dimensional Discrete Fourier Transform
F i f i M N i l
1 1M N2-D DFT
For an image of size MxN pixels
∑∑−
=
−
=
+−=1
0
1
0
)//(2),(1),(M
x
N
y
NvyMuxjeyxfMN
vuF π
= =0 0x y
u = frequency in x direction, u = 0 ,…, M-1v = frequency in y direction v = 0 N-1
2-D IDFT
v frequency in y direction, v 0 ,…, N 1
∑∑− −
+=1
0
1
0
)//(2),(),(M N
NvyMuxjevuFyxf π
0 M 1= =0 0u v x = 0 ,…, M-1y = 0 ,…, N-1
Chapter 42 Di i l Di t F i T f ( t )
Chapter 42 Di i l Di t F i T f ( t )2-Dimensional Discrete Fourier Transform (cont.)2-Dimensional Discrete Fourier Transform (cont.)
F(u,v) can be written asF(u,v) can be written as),(),(),( vujevuFvuF φ−=or),(),(),( vujIvuRvuF +=
22 )()()( vuIvuRvuF +
where
⎟⎟⎞
⎜⎜⎛− ),(tan)( 1 vuIvuφ),(),(),( vuIvuRvuF += ⎟⎟
⎠⎜⎜⎝
=),()(tan),(
vuRvuφ
For the purpose of viewing, we usually display only theMagnitude part of F(u,v)ag ude pa o (u,v)
Chapter 4Relation Between Spatial and Frequency
l i
Chapter 4Relation Between Spatial and Frequency
l iResolutionsResolutions
u =Δ1
Nv
Δ=Δ
1xMΔ yNΔ
whereΔx = spatial resolution in x directionΔy = spatial resolution in y direction
( Δx and Δy are pixel width and height. )
Δu = frequency resolution in x directionΔv = frequency resolution in y directionN,M = image width and height
Displaying transforms
• Having obtained the Fourier transform F(u) of a signal f(x), what does it look like?
• Having obtained the Fourier transform F(u,v) of an image f(x,y), what does it look like?g f( y)
• F(u,v) are complex number, we can’t view them directly, but we view their magnitudedirectly, but we view their magnitude |F(u,v)| . We have 3 approaches– 1. Find the maximum value m of |F(u v)| ( DC term), and1. Find the maximum value m of |F(u,v)| ( DC term), and
use imshow to view |F(u,v)| /m– 2. use mat2gray to view |F(u,v)| directlyg y | ( , )| y– 3. use imshow to view log(1+ |F(u,v)| )
Chapter 4Periodicity of 1-D DFT
Chapter 4Periodicity of 1-D DFT
∑−
−=1
0
/2)(1)(M
x
NuxjexfN
uF πFrom DFT:=0xN
0 N 2N-N 0 N 2N-N
DFT repeats itself every N points (Period = N) but we usuallyWe display only in this range
DFT repeats itself every N points (Period N) but we usually display it for n = 0 ,…, N-1
Chapter 4Conventional Display for 1-D DFT
Chapter 4Conventional Display for 1-D DFT
)(uFDFTf(x)
0 N-1
Time Domain Signal
0 N-1
g
L f
High frequencyarea
Low frequencyarea
The graph F(u) is notThe graph F(u) is not easy to understand !
Chapter 4Conventional Display for DFT : FFT Shift
Chapter 4Conventional Display for DFT : FFT Shift
)(uF )(uFFFT Shift: Shift center of thegraph F(u) to 0 to get betterDisplay which is easier to
)(uF0 N 1
Display which is easier to understand.
)(uF0 N-1
High frequency area
0-N/2 N/2-1Low frequency area
Chapter 4Periodicity of 2-D DFT
Chapter 4Periodicity of 2-D DFT
∑∑− −
+−=1 1
)//(2),(1),(M N
NvyMuxjeyxfMN
vuF π2-D DFT: ∑∑= =0 0x yMN
-M
g(x y)
0
g(x,y)
For an image of size NxMpixels, its 2-D DFT repeats
0
itself every N points in x-direction and every M points in y direction
M
in y-direction.
We display only 2M in this range
0 N 2N-N
2M
(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.
Chapter 4C ti l Di l f 2 D DFT
Chapter 4C ti l Di l f 2 D DFTConventional Display for 2-D DFTConventional Display for 2-D DFT
F(u,v) has low frequency areasat corners of the image while highat corners of the image while highfrequency areas are at the centerof the image which is inconvenientgto interpret.
High frequency area
Low frequency area
Chapter 42 D FFT Shift : Better Display of 2 D DFT
Chapter 42 D FFT Shift : Better Display of 2 D DFT
2-D FFT Shift is a MATLAB function: Shift the zero frequency of F(u v) to the center of an image
2-D FFT Shift : Better Display of 2-D DFT2-D FFT Shift : Better Display of 2-D DFT
Shift the zero frequency of F(u,v) to the center of an image.
2D FFTSHIFT2D FFTSHIFT
High frequency area Low frequency area(Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.
Chapter 42 D FFT Shift (cont ) : How it works
Chapter 42 D FFT Shift (cont ) : How it works
M
2-D FFT Shift (cont.) : How it works2-D FFT Shift (cont.) : How it works
-M
0
Display of 2D DFTAfter FFT Shift
MS
Original displayof 2D DFT
2Mof 2D DFT
0 N 2N-N
Chapter 4Example of DFT
Chapter 4Example of DFT
• Fourier transforms in MatlabThe relevant Matlab functions for us are:The relevant Matlab functions for us are:
– fft which takes the DFT of a vector,iff hi h k h i DFT f– ifft which takes the inverse DFT of a vector,
– fft2 which takes the DFT of a matrix,– ifft2 which takes the inverse DFT of a matrix,– fftshift which shifts a transformfftshift which shifts a transform.
Chapter 4Example of DFT
Chapter 4Example of DFT
• Example 1Example 1
Note that the DC coecient is indeed the sum of all theNote that the DC coecient is indeed the sum of all the matrix values.
Chapter 4Example of DFT
Chapter 4Example of DFT
• Example 2Example 2
Chapter 4Example of DFT
Chapter 4Example of DFT
E l 3• Example 3
Chapter 4Fourier transforms of images
Chapter 4Fourier transforms of images
• Example 1>> a=[zeros(256 128) ones(256 128)];>> a=[zeros(256,128) ones(256,128)];>> af=fftshift(fft2(a));>> fm = max(af(:));>> imshow(im2uint8(af/fm));( ( ))
b ( 329)&( 182)&( 67)&( 73)>> b=(x+y<329)&(x+y>182)&(x-y>-67)&(x-y<73);>> imshow(b)>> bf=fftshift(fft2(b));>> bf fftshift(fft2(b));>> fm = max(bf(:));>> imshow(im2uint8(bf/fm));
Chapter 4Fourier transforms of images
Chapter 4Fourier transforms of images
E l 4• Example 4>> [x,y]=meshgrid(-128:217,-128:127);>> z=sqrt(x.^2+y.^2);>> c=(z<15);>> imshow(c);>> cf=fft2shift(fft2(c));>> figure,fftshow(af,'abs')
Chapter 4Example of 2 D DFT
Chapter 4Example of 2 D DFTExample of 2-D DFTExample of 2-D DFT
Notice that the longer the time domain signalNotice that the longer the time domain signal,The shorter its Fourier transform
Chapter 4Example of 2-D DFT
Chapter 4Example of 2-D DFTpp
Notice that direction of an object in spatial image andobject in spatial image andIts Fourier transform are orthogonal to each other.
Chapter 4Example of 2-D DFT
Chapter 4Example of 2-D DFT
2D DFT
Example of 2 D DFTExample of 2 D DFT
2D DFT
Original image
2D FFT Shift
Chapter 4Example of 2-D DFT
f = zeros(30,30);f(5:24 13:17) = 1;f(5:24,13:17) 1;figure;imshow(f,'notruesize');F = fft2(f);( )F2 = log(abs(F)+1);figure;imshow(F2,[-1 5],'notruesize'); F3 l ( b (fft hift(F))+1)F3=log(abs(fftshift(F))+1);figure;imshow(F3,[-1 5],'notruesize');
Chapter 4Example of 2-D DFT
Chapter 4Example of 2-D DFT
2D DFT
Example of 2 D DFTExample of 2 D DFT
2D DFT
Original image
2D FFT Shift
Chapter 4Basic Concept of Filtering in the Frequency Domain
Chapter 4Basic Concept of Filtering in the Frequency Domain
From Fourier Transform Property:
Basic Concept of Filtering in the Frequency DomainBasic Concept of Filtering in the Frequency Domain
),(),(),(),(),(),( vuGvuHvuFyxhyxfyxg =⋅⇔∗=
We cam perform filtering process by usingWe cam perform filtering process by using
M ltiplication in the freq enc domainMultiplication in the frequency domainis easier than convolution in the spatialDomain.
Filtering in the Frequency Domain with FFT shiftFiltering in the Frequency Domain with FFT shift
F(u,v) H(u,v)(User defined) g(x,y)
FFT hifFFT shift 2D IFFTX
2D FFT FFT shift
f(x,y) G(u,v)f(x,y) G(u,v)
In this case, F(u,v) and H(u,v) must have the same size andhave the zero frequency at the center.
Multiplication in Freq. Domain = Circular ConvolutionMultiplication in Freq. Domain = Circular Convolutionf( ) DFT F( )f(x) DFT F(u)
G(u) = F(u)H(u) h(x) DFT H(u)
g(x)IDFT
1
h(x) DFT H(u)
Multiplication of DFT f 2 i l f( )
0 20 0 60 80 100 1200
0.5DFTs of 2 signalsis equivalent toperform circular
f(x)
0 20 40 60 80 100 120
0 5
1
perform circular convolutionin the spatial domain.
h( )
0 20 40 60 80 100 1200
0.5 h(x)
“Wrap around” effect 0 20 40 60 80 100 120
40g(x)
p
0 20 40 60 80 100 1200
20g(x)
convolution_discrete_B.swf
Applications of the Fourier TransformApplications of the Fourier TransformApplications of the Fourier TransformApplications of the Fourier TransformLocating Image Features
Th F i f l b d f l i hi hThe Fourier transform can also be used to perform correlation, which is closely related to convolution. Correlation can be used to locate features within an image; in this context correlation is often calledfeatures within an image; in this context correlation is often called template matching.
Results of Gaussian Results of Gaussian Results of Gaussian Lowpass Filters
Results of Gaussian Lowpass Filters
No ringing effect!
Application of Gaussian Lowpass FiltersApplication of Gaussian Lowpass Filters
Better LookingOriginal image
Th GLPF b d t j d dThe GLPF can be used to remove jagged edges and “repair” broken characters.
Application of Gaussian Lowpass Filters (cont.) Application of Gaussian Lowpass Filters (cont.) R i klRemove wrinkles
Original image
Softer-Looking
Application of Gaussian Lowpass Filters (cont.) Application of Gaussian Lowpass Filters (cont.)
Filtered imageOriginal image : The gulf of Mexico and Filtered imageOriginal image : The gulf of Mexico andFlorida from NOAA satellite. (Images from Rafael C. Gonzalez and Richard E.
Wood, Digital Image Processing, 2nd Edition.
Remove artifact lines: this is a simple but crude way to do it!
Hi h Filt Hi h Filt Highpass Filters Highpass Filters
Gaussian Highpass Filters (cont.) Gaussian Highpass Filters (cont.) g p ( )g p ( )
20
2 2/),(1),( DvuDevuH −−=1
0.6
0.8
Gaussian highpass filter with D = 5
0
0.2
0.4 filter with D0 = 5
1020
3040
5060
20
40
60
2000
3000
0
1000Spatial respones of the Gaussian highpass filter
ith D 5
1020
3040
5060
20
40
60with D0 = 5
Spatial Responses of Highpass Filters Spatial Responses of Highpass Filters
Ripplespp
R lt f Id l Hi h Filt R lt f Id l Hi h Filt Results of Ideal Highpass Filters Results of Ideal Highpass Filters
Ringing effect can be b i l !obviously seen!
R lt f B tt th Hi h Filt R lt f B tt th Hi h Filt Results of Butterworth Highpass Filters Results of Butterworth Highpass Filters
Results of Gaussian Highpass Filters Results of Gaussian Highpass Filters g pg p
Laplacian Filter in the Frequency DomainLaplacian Filter in the Frequency Domain
( ) )()( uFjuxfd nn
⇔
From Fourier Tr. Property:
( ) )(uFjudxn ⇔
Then for Laplacian operator22 ff ∂∂ ( ) ),(22
2
2
2
22 vuFvu
yf
xff +−⇔
∂∂
+∂∂
=∇
We get( )222 vu +−⇔∇
We get
Image ofg–(u2+v2)
Surface plot
Laplacian Filter in the Frequency Domain (cont.)Laplacian Filter in the Frequency Domain (cont.)
Spatial response of –(u2+v2) Cross section
Laplacian mask in Chapter 3p p
Sharpening Filtering in the Frequency DomainSharpening Filtering in the Frequency DomainSharpening Filtering in the Frequency DomainSharpening Filtering in the Frequency Domain
Linear Convolution by using Circular Convolution and Zero Padding Linear Convolution by using Circular Convolution and Zero Padding
The discrete Fourier transform assumes a The discrete Fourier transform assumes a transform assumes a digital image exists on a closed surface, a torus.
transform assumes a digital image exists on a closed surface, a torus.
Linear Convolution by using Circular Convolution and Zero Padding Linear Convolution by using Circular Convolution and Zero Padding
Linear Convolution by using Circular Convolution and Zero Padding Linear Convolution by using Circular Convolution and Zero Padding
Filtered image
Zero padding area in the spatialDomain of the mask image(th id l l filt )