1
Maria Magnusson, Computer Vision Lab., Dept. of Electrical Engineering, LinkΓΆping University
Digital Image Processing Lecture 3 DFT and the relation to continuous Fourier transform 2D convolution 2D filters: low-pass, high-pass, derivative (sobel) Circular convolution The magnitude of the gradient and edge enhancement
Gonzales & Woods: Chapter 3, 25 pages Chapter 4, 65 pages
Numbers according to Gonzales & Woods, Global Edition, 4th edition. (Numbers in other editions may vary).
p. 1
Another equation for the Fourier trans-form of the impulse train sampled signal
πΊ π π π‘ βπ ππ‘
π π‘ β πΏ π‘ πΞ βπ ππ‘
π π‘ πΏ π‘ πΞ βπ ππ‘
βπ π‘ πΏ π‘ πΞ βπ ππ‘
π πΞ π π π
β(4-40)
p. 2
DFT (Discrete Fourier transform),symmetric
πΊ π π / ,βπ2 π
π2 1
/
/
Comparison with previous slide gives: πΊ πΊπ
πΞif π 0 outside π:s interval.ββπΊ βis a scaled variant of πΊ .
DFT
π1π πΊ π / ,β
π2 π
π2 1
/
/
Inverse DFT
ππ
πΞScaling between continuous and
discrete frequenses:
p. 3 Continuous Fourier transform & DFTSignal domain Fourier domain
p. 4
2
DFT (Discrete Fourier transform),symmetric and normal
πΊ π π / ,β/
/
π2 π
π2 1
DFT
, sym
met
ric
π1π πΊ π /
/
/
,βπ2 π
π2 1D
FT, n
orm
al πΊ π π / , β0 π π 1
π1π πΊ π / , 0 π π 1
Matlab:
fftsh
ift(ff
t(ifft
shift
( )))
iffts
hift(
ifft(f
ftshi
ft( ))
)
Matlab:
fft( )
ifft(
)
β(4-42)
β(4-43)
p. 5
About the relations between conti-nuous Fourier transform and DFT⦠A time-limited signal can not be band-limited. A band-limited signal can not be time-limited. DFT demands a time-limited signal. The sampling theorem demands a band-limited
signal. Therefore, the continuous Fourier transform can only
be calculated approximately with sampling and DFT. DFT can be calculated fast with FFT (Fast Fourier
Transform). For N points, the complexity of DFT is O(N2). For N points, the complexity of FFT is O(N logN). There are more about FFT (outside the course) in
chapter 4 if you are interested.
p. 6
2D DFT, normalπΉ π’, π£ π π₯, π¦ π / /
π π₯, π¦1
ππ πΉ π’, π£ π / /
πΉ π’, π£ π π₯, π¦ π / /
π π₯, π¦ π / βπ /
β(4-67)
β(4-68)
can be separated
Can you write down the 2D Symmetric DFT?
p. 7 1D and 2D continuous and discrete convolution
Continuous convolution
π€ β π π₯ π€ π₯ πΌ β π πΌ ππΌ
π€ β π π₯ π€ π₯ πΌ β π πΌ
Discrete convolution
π€ β π π₯, π¦ π€ π₯ πΌ, π¦ π½ β π πΌ, π½ ππΌππ½
π€ β π π₯, π¦ π€ π₯ πΌ, π¦ π½ β π πΌ, π½
β(4.24)
p. 8
3
β π π₯ 0,0,0,1,1,1,0,0 βπ€ π₯ 0,0,0,3,2,1,0,0π€ β π π₯ 0,0,3,5,6,3,1,0
1D discrete convolution1 113 125 363 1
π₯ 0
1 11 32
5 363 1
1 π πΌπ€ π₯ πΌ
π€ β π π₯ in x-space
in -space
π₯ 0
πΌ 0
π€ β π π₯ π€ π₯ πΌ β π πΌ
Mirroredfilter
p. 9
Fig. 3.28
π π₯, π¦π€ 1, 1 π π₯ 1, π¦ 1
π€ 1,0 π π₯ 1, π¦ . . .π€ 0,0 π π₯, π¦ . . .π€ 1,1 π π₯ 1, π¦ 1
The mecha-nics of linear spatial filtering using a 3x3 filter mask
The resultg(x,y) is put inthe out-imageat the placeof the filter
origin.
p. 10
0 0
π π₯, π¦ π€ π₯, π¦
00 -2
1
1
000
0 0-2
3
1
000
0
2D discrete convolution
00
-2
1
1
000
00
0 0
0
3
400 0
4 -4
0
0
1
-80
00
0
0
0
000
β π₯, π¦ π€ β π π₯, π¦ π€ π₯ πΌ, π¦ π½ β π πΌ, π½
β π₯, π¦ π β π€ π₯, π¦ π π₯ πΌ, π¦ π½ β π€ πΌ, π½
00
0 0
0
3
400 0
4 -4
0
0
1
-80
00
0
0
0
0000
00 0
000 0
0
00
00
0
0
0
000*
The filter must be mirrored in the x- and
y-axis, i.e. rotated 180o!
p. 11 Which Fourier transformhas this filter? Put dirac impulses at every value in the filter. Set
the sample distance to . This gives:
Compute the continuous Fourier transform, use the formula collection. This gives:
πΉ π’ 1 β 1 β π 2 β 1 1 β 1 β π /4
2 cos 2πΞπ’ 2 /4 cos πΞπ’
π π₯ 1 β πΏ π₯ Ξ 2 β πΏ π₯ 1 β πΏ π₯ Ξ /4
1 1 /42
p. 12
π₯
1/2
Ξ
4
Alternative. Compute the DFT of the filter: Here is the filter drawn as fD(n):
Insert fD(n) into the DFT formula:
πΉ π π π βπ / β/
/
β― 0 1 β π / . . .β
. . . 2 β π / 1 β π / 0 β― /4 β 2 cos 2ππ/π 2 /4 β cos ππ/π
1 1 /42
p. 13
π’ π πΞβScaling between continuous and discrete frequenses:
π1
1/2
A 1D discrete weighted averag-ing filter is also a low-pass filter
cos πΞπ’
Attenuates high frequencies1 1 /42
Filter withdirac impulses
Fourier transform
Set the sample distance to
Filter
π’Ξ
1 2β
π₯
p. 14
Which 2D Fourier transformhas this filter? Put dirac impulses (x,y)=(x)(y) at every value
in the filter. Set the sample distance to . This gives
Compute the continuous Fourier transform
πΉ π’, π£ 1 β π 2 1 β π β 1 π£ /4 ββ
2 cos 2πΞπ’ 2 /4 cos πΞπ’
π π₯, π¦ 1 β πΏ π₯ Ξ 2 β πΏ π₯ 1 β πΏ π₯ Ξ β πΏ π¦ /4
1 1 /42
p. 15 Low-pass filter in the x- (u-) direction
cos πΞuΞ 1βhere
1 1/4
2 x
y
u
v
p. 16
5
Low-pass filter in the y- (v-) direction
cos πΞvΞ 1βhere
1
1
/4
2 x
y
u
v
p. 17 Low-pass filter in the x- (u-) direction and the y- (v-) direction
cos πΞu β cos πΞvΞ 1βhere
Attenuates high frequencies
11
2
2 *
=1
1
2
221
14
1
1/4
/4
/16
2
p. 18
A 3x3 averaging filter anda 3x3 weighted averaging filter
A (weighted) averaging filter must be divided by the sum of the values of its coefficients.
The averaging filter have relatives of size 5x5, 7x7, 9x9, β¦They do all have a sincΓsinc-like Fourier transform.
Fig. 3.31
p. 19
Smoothing withaveraging filters
5x5
15x1
5
3x3
9x9
35x3
5
The smoothing is not symmetric in all
directions and the sincΓsinc-like
Fourier transform is not the best choice.
Why is it a dark frame around some images?
Similar to Fig. 3.33
Noise is attenuated.Details and edges
are blurred.
p. 20
6
Image size after 2D linear discrete convolution Valid: Values outside the in-image are regarded as undefined =>
The out-image becomes smaller than the in-image. Full: Values outside the in-image are regarded as zero => The out-
image becomes bigger than the in-image. Or equally sized if the extra values are thrown away. (Same)
To avoid bordereffects, theborder pixels inthe image can be extrapolated beforeconvolution.
p. 21
h, rotated
More low-pass filter in the x- (u-) direction and the y- (v-) direction
cos πΞu β cos πΞvΞ 1βhere
24 =16
16
24
242416
1636
/256
21
1
2
221
14
/16
21
1
2
221
14
/16
464
464
64
464
41 1
11
*
p. 22
*
Low-pass filteringin the spatial domain
2416
16
24
242416
1636
/256
464
464
64
464
41 1
11
p. 23 Low-pass filtering inthe Fourier domain
p. 24Fourier transform
7
π22 π11 2 β π12 βπ13 . . . β2 β π21 4 β π22 2 β π23 . . . βπ31 2 β π32 βπ33
Computational complexityfor discrete convolution
5 multiplications and 8 additions per pixel!
p. 25
6 multiplications,8 additions and1 division per pixel
21 multiplications,24 additions and1 division per pixel
2
Computational complexitywith and without separation
24 =16
16
24
242416
1636
/256
464
464
64
464
41 1
11
21
1
1
1
/256
*
p. 26
2 424
Gaussian low-pass filters (GLPF) designed in the Fourier Domain
π» π’, π£ π , β
Fig. 4.43
(4-116)
The filters on the previous slides belongs to a family with separa-ble weighted averaging filters based on the binomial coefficients. They approximates Gaussian functions. However, Gaussian low-pass filters can also be designed directly in the Fourier domain.
p. 27
Not
e: T
he u
-and
v-a
xis
shou
ld ra
ther
pas
s th
e ce
nter
of t
he im
age.
Similar to Fig. 3.36-3.37
Smoothing withGLPF filters
3016
0
Cut
off f
req.
=10
6046
0
The smoothing is symmetric all
directions, i.e. rotational symmetric.
Noise are attenuated.Details and edges
are blurred.
p. 28
8
Ideal low-pass filters (ILPF) designed in the Fourier Domain
π» π’, π£ 1 if π· π’, π£ π·0 if π· π’, π£ π·
Fig. 4.39
(4-111)
(4-112)π· π’, π£ π’ π/2 π£ π/2
p. 29
Note: The u- and v-axis should ratherpass thecenter of the image.
Similar to Fig. 4.41
Smoothing withILPF filters
3016
0
Cut
off f
req.
=10
6046
0
Noise are attenuated.Details and edges
are blurred.
Note the Gibbsringing artefacts!
The smoothing is symmetric all
directions, i.e. rotational symmetric.
p. 30
Multiplication in the discrete Fourier do-main corresponds to circular convolution
Is performed via multiplication in theFourier domain. The out-image gets the same size asthe in-image.
Convo-lutionkernel
zerosβ¦
zerosβ¦
Can be pre-calculated
In-image Out-image
1D circular convolution
π β β π π π β β π π
whereβ β denotes circular convolution and denotes modulo π operation,i.e. β βcan be viewed as periodical repeatedor circular.Theorem:βπ·πΉπ π β β π πΉ π β π» π
p. 32
9
**
Zero-padding must be performed before circular convolutionto get the same result as normal linear convolution.
= =
1D circular convolution
p. 33 Example) 2D linear and circular convolution
In-image Averaging filterSize: 15x15
Peter Forsberg,former hockey player
p. 34
Example) 2D linear and circular convolution
Out-image after linear convolution
Out-image after circular convolution
p. 35
Computing the derivative = convolution with a derivative operator
Fourier transform
π sin 2πΞπ’ /Ξ
Derivative filter:
1 -1/2
0
A filter that have a Fourier transform looking like a straight line through the origin can be used as a derivative filter.
πππ₯
π2ππ’
Fourier transform
p. 36
π sin 2πΞπ’ /Ξ β π2πΞπ’/Ξ==π2ππ’, for small π’
10
Derivative filter plus low-pass in the x- (u-) direction
1 -1/2
0 x
y uv
p. 37
π sin 2πΞπ’ /Ξ,Ξ 1βhere
Derivative filter plus low-pass in the y- (v-) direction
π sin 2πΞπ£ /Ξ,Ξ 1βhere
1
-1
/2
0 x
y
u
v
p. 38
Derivative filter in the x- (u-) direction plus low-pass filter in both directions
π sin 2πΞπ’ β cos πΞπ£ /Ξ,Ξ 1βhere
-11
-2
0
=-1
-1
0
021
10
1
1/4
/2
/8
2
Sobel-x
βFig. 4.38
*
p. 39
Derivative filter in the y- (v-) direction plus low-pass filter in both directions
π sin 2πΞπ£ β cos πΞπ’ /Ξ,Ξ 1βhere
11
0
2
=-1
1
-2
20-1
10
-1
1/2
/4
/8
0
Sobel-y
*
p. 40
11
-1/8
-2 -10 0 01 2 1
ππ π₯, π¦ππ₯
ππ π₯, π¦ππ¦
x
y
gray scalecolortable:βββ0 β black127 β gray255 β white
bipolarcolortable:
128 β blue β0 β white127 β red
π π₯, π¦
convolve
121 0
00
-1-2-1
/8
Derivative filtering p. 41 The magnitude of the gradient enhances edges in the image
π π₯, π¦βπ π₯, π¦
ππ π₯, π¦ππ₯
ππ π₯, π¦ππ¦
Magnitude of the gradientIn-image
βπ π₯, π¦
ππ π₯, π¦ππ₯
ππ π₯, π¦ππ¦
ππ
p. 42
Derivative filtering and edge enhancement
-128
=bla
ck12
7=w
hite
π: originalπ π
0=bl
ack
255=
whi
te
π π
p. 43
Linear discrete convolution whenthe center is between the pixels
1* =-11 1 -11 0
1* =-11 1
-1
10
p. 44
πππ₯ β lowpass
filter π
ππ₯
πππ¦ β lowpass
filter π
ππ¦
/2
/2/
/ /2
/2
12
In a similar way as on previous slide, we can construct a Laplace filter
Fig. 3.45
Mask a Mask b
p. 45
Lab 1 exercise
β ππ πππ₯
π πππ¦
πππ₯ β
πππ₯
πππ¦ β
πππ¦ β¦ Mask a
Laplace can help to give a shaper image π π₯, π¦ π π₯, π¦ π β π π₯, π¦
Fig. 3.46
(3-54)
π π₯, π¦ β π π₯, π¦
π π₯, π¦UsingMask a
UsingMask b
π π₯, π¦
Note that c = -1 !
p. 46
A normal approximate Laplace filter mask = a high-pass filter β’ -1
1 =0
0
1
110
0-4
/
11 -2/
1
1-2
/
+
4 sin πΞπ’ sin πΞπ£ Ξβ
p. 47
Fourier transform
β 1, 2,1 Ξβ : 1 β π 2 1 β π /Ξ ββ
2 cos 2πΞπ’ 2 /Ξ 4 β sin πΞπ’ /Ξ
Fig. 4.30
Low- and High-pass filtering p. 48
Top Related