Professional Documents
Culture Documents
Kokaram
www.mee.tcd.ie/sigmedia
A. C. Kokaram
Transforms Overview
2D Fourier Transform
Sampling Theorem
2D Z-transform
2D Filters and stability
Some applications and the need for non-linear filters
www.mee.tcd.ie/sigmedia
A. C. Kokaram
2D Fourier Analysis
Idea is to represent a signal as a sum of pure sinusoids of different amplitudes and frequencies.
In 1D the sinusoids are defined by frequency and amplitude.
In 2D these sinusoids have a direction as well e.g. f (x, y) = a cos(1 x + 2 y + )
10
20
0.5
30
0.5
40
1
80
70
60
50
60
50
40
40
30
20
20
0
10
0
60
10
20
30
40
50
60
a = 1.0 1 = 0.29 2 = 0.11 Wave is directed at 20 degrees off horizontal, frequency is 0.05 cycles per
pel in that direction and phase lag phi = 0.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
10
x cos
In the direction :
a cos(0 + ), where
some phase lag.
f ()
is
=
just
20
y sin
30
50
60
10
20
30
40
50
60
www.mee.tcd.ie/sigmedia
A. C. Kokaram
(2)
2D Fourier Transform is similar. except with TWO frequency axes for horizontal
and vertical frequency.
Z
F (1 , 2 ) =
f (x, y) =
y= x=
Z
Z
1
4 2
2 =
1 =
F (1 , 2 )ej(1 x+2 y) d1 d2
(3)
Parseval:
|f (x, y)|2 =
F
(
,
)F
(1 , 2 )d1 d2
1
2
2
4
2 1
y x
www.mee.tcd.ie/sigmedia
A. C. Kokaram
Z
F (1 , 2 ) =
Z
y=
x=
=
y=
(4)
x=
Can do 1D transform of rows first then do 1-D transform of result along columns.
Or vice-versa.
Fourier Xform of separable signals is also separable. Let f (x, y) = fx (x)fy (y) then
F (1 , 2 ) = Fx (1 )Fy (2 ). [Note that this is different from convolution identity
because the signal is SEPARABLE!].
www.mee.tcd.ie/sigmedia
A. C. Kokaram
height = c
b
3
4
4
y x
Z a/2
f (x, y)e
sin(1 b/2)
0.8
0.6
= bcsinc
0.2
0
4
4
2
2
Vertical xform: F (1 , 2 ) =
2
Y
2
4
Z b/2
j(1 x+2 y)
ce
dx dy
y=a/2 x=b/2
"Z
Z a/2
b/2
= 2c
0.4
j(1 x+2 y)
dx dy
#
j1 x
j2 y
ce
dx e
dy
x=b/2
y=a/2
3
2
#
"Z
j1 x b/2
e
b/2
j1 x
5
ce
dx = c 4
x=b/2
j1
b/2
c
j1 b/2
j1 b/2
=
e
e
j1
=
Z a/2
a/2
1
1 b
= bc
sin(1 b/2)
1 b/2
2
j2 y
bcsinc(1 b/2)e
dy
= bcsinc(1 b/2)
Z a/2
a/2
j2 y
e
dy
www.mee.tcd.ie/sigmedia
A. C. Kokaram
6
3
height = c
f (x, y)
0
2
4
2
b
3
4
4
8
8
3
0
1
F (1 , 2 )
1
0.8
0.5
0.6
f (x, y)
0.4
0.2
0.5
10
0
4
10
2
2
2
Y
2
4
5
2
5
10
10
F (1 , 2 )
www.mee.tcd.ie/sigmedia
A. C. Kokaram
Given f (x, y) F (1 , 2 )
Shift Theorem f (x dx , y dy ) F (1 , 2 )ej(1 dx +2 dy )
` 1 T
1
Coordinate Xformation f (Ax)
F( A
)
||A||
where x = [x y]T and A is a 2 2 matrix representing a general 2D transformation
e.g.
2
2
3
3
a 0
cos sin
5 Rotation A = 4
5
Zoom A = 4
(5)
0 a
sin
cos
2
3
2
3
1/a
0
cos sin
5 Rotation (A1 )T = 4
5
Zoom (A1 )T = 4
(6)
0
1/a
sin
cos
Therefore, magnifying the image by a factor a (zooming), causes the spectrum to
shrink in area by that factor.
Rotating an image by causes the spectrum to rotate by the same angle.
Image and Video Processing, Trinity College, Dublin.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
10
Most natural images have an exponential drop off in spectral power with increasing frequency
Taking transform of signal causes compaction of energy into low-f regions
www.mee.tcd.ie/sigmedia
A. C. Kokaram
11
www.mee.tcd.ie/sigmedia
A. C. Kokaram
12
Given
f (x, y) F (1 , 2 )
Z Z
1
F (1 , 2 ) =
f (x, y)ej(1 x+2 y) dx dy
2
4 y x
(7)
j(1 x+2 y)
F (1 , 2 ) =
f
(x,
y)e
dx dy
4 2 y x
Z Z
1
f (x, y) is real
=
f (x, y)ej(1 x+2 y) dx dy
2
4 y x
cf equation 7
= F (1 , 2 ) QED
(8)
Just two quadrants specify the FT of an image with real valued pixels. See this from
the pics previously
Image and Video Processing, Trinity College, Dublin.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
13
(x n1 Dx , y n2 Dy )
(9)
n1 = n2 =
where Dx , Dy are the separations between points on the sampling grid i.e. the period of horizontal and
vertical sampling, and Dx Dy is just used as a normalising constant. Sampling (or digitization) is modelled
as fs (x, y) = f (x, y)s(x, y). Now want to find out the relationship between F (1 , 2 ) and Fs (1 , 2 ).
Dx
x
Dy
2
1111
0000
0000
1111
0000
1111
0000
1111
0000
1111
0000
0000
1111
1111
1
0000
1 1111
0000
1111
Left: s(x, y): each dot is a function coming out of the plane of the page. Right: F (1 , 2 ), we assume
that the spectrum of f (x, y) is bandlimited between 1 and 2 respectively.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
14
Convenient to use 2D Fourier series to express s(x, y) (since its a periodic function) before proceeding.
s(x, y) =
k1 = k2 =
0,
where 1
0 = 2 ,
2
Dx
ak ,k =
1 2
Dx Dy
(10)
0 x+k 0 y)
j(k1 1
2 2
ak ,k e
1 2
1
Dx Dy
1
Dx Dy
Z
y
Z
x
0 x+k 0 y)
j(k1 1
2 2
s(x, y)e
dx dy
Z D /2
y
Z D /2
x
y=Dy /2 x=Dx /2
0 x+k 0 y)
j(k1 1
2 2
Dx Dy (x, y)e
dx dy
(11)
0 x+k 0 y)
j(k1 1
2 2
e
(12)
k1 = k2 =
www.mee.tcd.ie/sigmedia
A. C. Kokaram
15
y x
Z Z
y
Z
From eq. 12 =
SO: Fs (1 , 2 ) =
x
Z
j(1 x+2 y)
fs (x, y)e
dx dy
j(1 x+2 y)
s(x, y)f (x, y)e
dx dy
2
6
4
x k = k =
1
2
k1 = k2 = y x
Z Z
X
X
k1 = k2 = y
3
0
0
j(k1 1 x+k2 2 y) 7
j(1 x+2 y)
e
dx dy
5f (x, y)e
f (x, y)e
0 x+k 0 y)
j(1 x+2 y) j(k1 1
2 2
e
dx dy
f (x, y)e
0 ]x+[ k 0 ]y)
j([1 k1 1
2
2 2
dx dy
0 ) etc
2 were replaced with (1 k1 1
k1 = k2 =
0
0
F (1 k1 1 , 2 k2 2 )
www.mee.tcd.ie/sigmedia
A. C. Kokaram
16
2D Sampling Theorem
1
1
0
2
F (1 , 2 )
2
1111
0000
0000
1111
0000
1111
0000
1111
0000
1111
0000
0000
1111
1111
1
0000
1 1111
0000
1111
0
1
1
2
Fs (1 , 2 )
0
1
0
2
For no overlap in the spectra to occur, 10 1 > 1 and 20 2 > 2 . Thus we get
Nyquists theorem for 2D (its similar to 1D).
10 > 21 AND 20 > 22
(13)
www.mee.tcd.ie/sigmedia
A. C. Kokaram
17
Aliasing
10
100
20
200
30
40
300
50
400
60
500
70
80
600
100
200
300
400
500
600
10
20
30
40
50
60
70
80
www.mee.tcd.ie/sigmedia
A. C. Kokaram
18
Aliased Lena
www.mee.tcd.ie/sigmedia
A. C. Kokaram
19
www.mee.tcd.ie/sigmedia
A. C. Kokaram
20
N
1 M
1
X
X
2 nh+ 2 mk
N
f (n, m)ej ( N
n=0 m=0
N 1 M 1
2
2
1 X X
f (n, m) =
F (h, k)ej ( N nh+ N mk)
N M h=0 k=0
(14)
For 0 h N 1, 0 k M 1 and 0 n N 1, 0
mM 1
Fast Algorithm exists (Lim pages 163182). Tedious to derive, wont bother, read
the book if you have to make devices/implementation. Note that most DSP
manufacturers supply FFT libraries, TI, Analog, Intel, (Matlab : fft, fft2) all
do. FFTW (Fastest Fourier Transform in the West) developed at MIT good for
general purpose processors see FFTW web site.
Image and Video Processing, Trinity College, Dublin.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
21
DFT calculates spec. components at equal intervals up till the sampling frequency. Given N M
transform: (0, 0)th bin is dc coeff and N 1th
bin 2/Dy similarly for M 1th bin.
1
0
2
0
1
0
2
1
DFT
samples
FT
here
0
1
F ((N
IW
(15)
www.mee.tcd.ie/sigmedia
A. C. Kokaram
22
The 2D z-transform
Recall 1D Z Transform of signal xn
X(z) =
xn z n
(16)
n=
(17)
n1 = n2 =
The z1 and z2 components act on the sequence p(h, k) along vertical and
horizontal directions in a sense.
Z transform in 2D is a function of 2 complex numbers z1 , z2 . It exists in a 4D
space so is very difficult to visualise.
Z-transform of a sequence is related to the spectral content of the sequence as
follows:
G(1 , 2 ) = G(ej1 , ej2 )
(18)
Image and Video Processing, Trinity College, Dublin.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
23
(19)
Given signal X(z1 , z2 ) input into a system with transfer function H(z1 , z2 ) output
Y (z1 , z2 ) is X(z1 , z2 )H(z1 , z2 ) [Just like 1D]
H(z1 , z2 ) = 4 z11 z1 z21 z2 is an FIR filter.
See this from difference equation if you like: Y (z1 , z2 ) = X(z1 , z2 )H(z1 , z2 )
therefore:
Y (z1 , z2 ) = X(z1 , z2 )(4 z11 z1 z21 z2 )
= 4X(z1 , z2 ) z11 X(z1 , z2 ) z1 X(z1 , z2 ) z21 X(z1 , z2 ) z2 X(z1 , z2 )
y(h, k) only depends on input x(h, k), so when input stops, output stops.
Or work out impulse response P (z1 , z2 ) p(h, k). Input is then
www.mee.tcd.ie/sigmedia
A. C. Kokaram
24
6
7
1
6
p(h, k) = Z
P (z1 , z2 ) 4 1
4
1 7
5
0
(20)
H1 (z1 , z2 )
H2 (z1 , z2 )
1
4 z11 z1 z21 z2
(21)
www.mee.tcd.ie/sigmedia
A. C. Kokaram
25
Corresponding difference equation given input x(h, k) and output defined as y(h, k):
Y (z1 , z2 ) = X()H()
=
X(z1 , z2 )
(4 z11 z1 z21 z2 )
y(h, k) =
1
(x(h, k) + y(h 1, k) + y(h + 1, k) + y(h, k 1) + y(h, k + 1))
4
(22)
Now output depends on previous outputs and outputs to come! IIR filter.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
26
Stability of filters
In 1D this criterion is exposed by examining the poles of the system and their
position relative to the unit circle.
Stability of non-separable 2D IIR filters is difficult to analyse. There is no
polynomial factorisation theorem for n-D, and we have a 4-D Z-Xform surface! No
notion of poles because H2 (z1 , z2 ) = 0 maps out a SURFACE.
We shall not bother with non-separable 2D IIR filter stability for this reason.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
27
We already dealt with filters that had a separable impulse response. Their system xfer
function is then
H(z1 , z2 ) = H1 (z1 )H2 (z2 )
(24)
These types of systems are implemented by processing along rows (or columns) and
then processing along columns (or rows). Revisit that low pass filter again.
Given H1 (z1 ) = z11 + 2 + z1 and H2 (z1 ) = z21 + 2 + z2 . What is the impulse
response of the system H1 (z1 , z2 )H2 (z1 , z2 )?
H(z1 , z2 ) = H1 (z1 )H2 (z2 )
= (z11 + 2 + z1 )(z21 + 2 + z2 )
www.mee.tcd.ie/sigmedia
A. C. Kokaram
28
separable filter
H(z , z )
1 2
H(z )
1 1
Row filter
H(z )
2 2
Column filter
www.mee.tcd.ie/sigmedia
A. C. Kokaram
29
Typically usable filters for images have a Zero (or linear) phase response
This implies that H(1 , 2 ) = H (1 , 2 ) i.e. the frequency response is a REAL
function. And as with 1D filters this implies that p(h, k) = p (h, k). This
means that the magnitude of the filter impulse response is also symmetric. For
real filters this condition implies that p(h, k) = p(h, k).
www.mee.tcd.ie/sigmedia
A. C. Kokaram
30
Filter Design
www.mee.tcd.ie/sigmedia
A. C. Kokaram
31
p(x, y) =
=
Z Z
j(1 x+2 y)
rect(, , 1)e
dx dy
4 2
1 Z Z
4 2
j(1 x+2 y)
e
dx dy
Z
1
2
j(1 y)
=
sin(x)
e
dy
2
4
x
=
4 2 x
1
4 2
sin(x)
2
y
sin(y)
2sinc(x)2sinc(y)
(26)
Filter is separable !
www.mee.tcd.ie/sigmedia
A. C. Kokaram
32
p(x, y) =
1
2sinc(x)2sinc(y)
4 2
But need to apply filter in digital domain. Recall sampling impulse train s(x, y)
previously. Samples at y = hD x = kD and recall scaling factor 1/(D D). Also
= 0 /(2N ) = (2/(2DN ) = (/(DN )
1
2
hD
2
kD
p(h, k) =
sinc
sinc
4 2 DN
DN
DN
DN
1
h
1
k
=
sinc
sinc
DN
N
DN
N
www.mee.tcd.ie/sigmedia
A. C. Kokaram
33
XX
h
Thus p(h, k) =
XX
h
1
sinc
N
h
N
1
sinc
N
k
N
So filter in digital domain is scaled by sampling frequency and so does not depend on the actual value of
the sampling frequency. (No different from 1D filters)
But sinc function is infinitely long so need to multiply impulse response by some data window w(h, k), to
reduce filter length intelligently to length N say. Use separable window w(h)w(k). Thus
p(h, k) =
where
w(h)
sinc
N
h
N
w(k)
sinc
N
8
<0.54 + 0.46 cos( m )
N
w(m) =
:0
k
N
|m| < N
(27)
Otherwise
See Lim Chapter 4 for FIR Filter Design and better design method: frequency
xformation pages 218238.
Image and Video Processing, Trinity College, Dublin.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
34
Implementation
P (1 , 2 )
0.3
0.25
0.2
0.15
0.1
20
0.05
0
0.05
20
20
20
10
10
40
0
10
10
20
60
20
80
100
120
0.5
0.5
0
0
Normalised Frequency
0.5
0.5
Normalised Frequency
www.mee.tcd.ie/sigmedia
A. C. Kokaram
35
Implementation
Original
20
50
40
100
60
150
80
200
100
120
250
50
100
150
200
250
20
40
60
80
100
120
20
20
20
40
40
60
60
40
60
80
80
100
100
80
120
120
20
40
60
80
100
120
20
40
60
80
100
120
100
120
20
40
60
80
100
120
www.mee.tcd.ie/sigmedia
A. C. Kokaram
36
SINC filter has to be quite long to do a reasonable job. (Used 33 taps in previous
example). Can cause ringing at edges, bad for image perception.
Can use simple average of 5 5 pel window, or Gaussian shaped filter (also
separable). Results acceptable for many apps.
!
!
2
2
h
k
p(h, k) exp
exp
2
2h
2k2
(28)
www.mee.tcd.ie/sigmedia
A. C. Kokaram
37
Given an observed signal g(h, k) = f (h, k) + (h, k) where f (h, k) is the clean original
and (h, k) N (0, 2 ); how do we recover f (h, k) from g(h, k)?
Can take approach that noise is visible because it creates a significant high
frequency component in the otherwise smooth image. So just using a low pass
filter to reduce the high-freq content of g(h, k) should do the trick.
But that kills image features like edges and so causes a reduction in sharpness.
Can use Frequency Domain Wiener filter H(1 , 2 ) (pages 354356 Lim) i.e.
F (1 , 2 ) = G(1 , 2 )H(1 , 2 ). The filter can be defined in terms of the PSD of
the signal f () and noise e() as
H(1 , 2 ) =
Pgf (1 , 2 )
Pf f (1 , 2 )
=
Pgg (1 , 2 )
Pf f (1 , 2 ) + P (1 , 2 )
=
Pgg (1 , 2 ) P (1 , 2 )
Pgg (1 , 2 )
=1
Pgg (1 , 2 )
P (1 , 2 )
(29)
Since is white Gaussian noise, its PSD is a constant across the whole spectrum.
This constant value 2 .
Image and Video Processing, Trinity College, Dublin.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
38
Can implement Wiener filter using |DFT|2 to estimate Power Spectrum of g().
BUT to estimate DFT of g() need to window the data with some analysis
window to prevent spectral leakage. Use 2D Hamming say (separable).
www.mee.tcd.ie/sigmedia
A. C. Kokaram
39
www.mee.tcd.ie/sigmedia
A. C. Kokaram
40
www.mee.tcd.ie/sigmedia
A. C. Kokaram
41
www.mee.tcd.ie/sigmedia
A. C. Kokaram
42
Impulsive noise cannot be easily removed with linear filters. Distortion occurs only at a subset of pel
sites and tends to take form of data dropout or data obliteration.
Median filter very useful in image processing for these kinds of defects. Idea is to define some N N
filter geometry and then the output of the filter is the median of the pixels in its window.
www.mee.tcd.ie/sigmedia
A. C. Kokaram
43
Problem is that median filter preserves gross image edges but ejects fine texture. Causes a kind of
flattening of detail.
This filter is one from the class of Order statistic filters. The output of this general class is some kind
of statistic measure of the pels in its window e.g. Upper Quartile, Lower Quartile etc. Need to
calculate histogram of pels in the window then select the pel at Q1 or Q3 etc.
Around 1990 a few researchers (Arce et al) spotted that you could improve the performance of the
median operator by cascading filter geometries. These are called multistage median filters.
10 3
200
14 14
15 14 14
11
11
00
00
11
11
00
00
11
11
00
00
00
1111
11
00
00
11
00
11
00
11
00
11
0011
11
00
00
11
11
00
00
11
11
00
00
11
11
00
00
Median
11
00
11
00
11
00
00
11
11
00
11
00
11
00
11
00
11
00
11
00
11
00
11
00
11
11
11
00
00
00
11
11
11
00
00
00
11
11
11
00
00
00
11
11
11
00
00
1100
1100
11
00
00
Median
Median
Median
www.mee.tcd.ie/sigmedia
A. C. Kokaram
44
Summary
www.mee.tcd.ie/sigmedia