C. A.
Bouman: Digital Image Processing - January 12, 2015 1
2-D Finite Impulse Response (FIR) Filters
• Difference equation
N
X N
X
y(m, n) = h(k, l)x(m − k, n − l)
k=−N l=−N
• For N = 2 - ◦ input points; × output point
◦ ◦ ◦ ◦ ◦
◦ ◦ ◦ ◦ ◦
◦ ◦ × ◦ ◦
◦ ◦ ◦ ◦ ◦
◦ ◦ ◦ ◦ ◦
• Number of multiplies per output point
Multiplies = (2N + 1)2
• Transfer function
N
X N
X
H(z1, z2) = h(k, l)z1−k z2−l
k=−N l=−N
XN XN
H(ejµ, ejν ) = h(k, l)e−j(kµ+lν)
k=−N l=−N
C. A. Bouman: Digital Image Processing - January 12, 2015 2
Spatial FIR Smoothing Filtering
• Filter point spread function (PSF) or impulse response:
The box, X , indicates the center element of the filter.
1 2 1
1
2 4 2 · 16
1 2 1
• Apply filter using free boundary condition: Assume that
pixels outside the image are 0.
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 3 4 4 3
0 0 0 16 16 16 16 ⇒ 0 0 3 9 12 12 9
0 0 0 16 16 16 16 0 0 4 12 16 16 12
0 0 0 16 16 16 16 0 0 4 12 16 16 12
0 0 0 16 16 16 16 0 0 3 9 12 12 9
| {z } | {z }
Input Image Output Image
C. A. Bouman: Digital Image Processing - January 12, 2015 3
PSF for FIR Smoothing Filter
1 2 1
1
2 4 2 · 16
1 2 1
C. A. Bouman: Digital Image Processing - January 12, 2015 4
Spatial FIR Horizontal Derivative Filtering
• Filter point spread function (PSF) or impulse response:
The box, X , indicates the center element of the filter.
2 0 −2
1
4 0 −4 · 16
2 0 −2
• Apply filter using free boundary condition: Assume that
pixels outside the image are 0.
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 2 2 0 0 −2
0 0 0 16 16 16 16 ⇒ 0 0 6 6 0 0 −6
0 0 0 16 16 16 16 0 0 8 8 0 0 −8
0 0 0 16 16 16 16 0 0 8 8 0 0 −8
0 0 0 16 16 16 16 0 0 6 6 0 0 −6
| {z } | {z }
Input Image Output Image
C. A. Bouman: Digital Image Processing - January 12, 2015 5
PSF of FIR Horizontal Derivative Filter
2 0 −2
1
4 0 −4 · 16
2 0 −2
C. A. Bouman: Digital Image Processing - January 12, 2015 6
Spatial FIR Vertical Derivative Filtering
• Filter point spread function (PSF) or impulse response:
The box, X , indicates the center element of the filter.
2 4 2
1
0 0 0 · 16
−2 −4 −2
• Apply filter using free boundary condition: Assume that
pixels outside the image are 0.
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 2 6 8 8 6
0 0 0 16 16 16 16 ⇒ 0 0 2 6 8 8 6
0 0 0 16 16 16 16 0 0 0 0 0 0 0
0 0 0 16 16 16 16 0 0 0 0 0 0 0
0 0 0 16 16 16 16 0 0 −2 −6 −8 −8 −6
| {z } | {z }
Input Image Output Image
C. A. Bouman: Digital Image Processing - January 12, 2015 7
PSF of FIR Vertical Derivative Filter
2 4 2
1
0 0 0 · 16
−2 −4 −2
C. A. Bouman: Digital Image Processing - January 12, 2015 8
Example 1: 2-D FIR Filter
• Consider the impulse response h(m, n) = h1(m)h1(n)
where
4h1(n) = (· · · , 0, 1, 2, 1, 0, · · · )
h1(n) = (δ(n + 1) + 2δ(n) + δ(n − 1))/4
Then h(m, n) is a separable function with
.. .. .. .. ..
0 0 0 0 0
··· 0 1 2 1 0 ···
16h(m, n) = · · · 0 2 4 2 0 · · ·
··· 0 1 2 1 0 ···
0 0 0 0 0
.. .. .. .. ..
• The DTFT of h1(n) is
1 jω jω −jω
H1(e ) = e +2+e
4
1
= (1 + cos(ω))
2
• The DSFT of h(m, n) is
H(ejµ, ejν ) = H1(ejµ)H1(ejν )
1
= (1 + cos(µ)) (1 + cos(ν))
4
C. A. Bouman: Digital Image Processing - January 12, 2015 9
Example 1: Frequency Response of 2-D FIR Filter
• Plot of frequency response
jµ jν 1
H(e , e ) = (1 + cos(µ)) (1 + cos(ν))
4
jµ jν
3−D Plot of H(e ,e )
0.8
0.6
0.4
0.2
0
4
2 4
2
0
0
−2
−2
−4 −4
ν axis
µ axis
• This is a low pass filter with H(ej0, ej0) = 1
C. A. Bouman: Digital Image Processing - January 12, 2015 10
Example 2: 2-D FIR Filter
• Consider the impulse response h(m, n) = h1(m)h1(n)
where
4h1(n) = (· · · , 0, 1, −2, 1, 0, · · · )
h1(n) = (δ(n + 1) − 2δ(n) + δ(n − 1))/4
Then h(m, n) is a separable function with
.. .. .. .. ..
0 0 0 0 0
· · · 0 1 −2 1 0 ···
16h(m, n) = · · · 0 −2 4 −2 0 ···
· · · 0 1 −2 1 0 ···
0 0 0 0 0
.. .. .. .. ..
• The DTFT of h1(n) is
1 jω jω−jω
H1(e ) = e −2+e
4
1
= − (1 − cos(ω))
2
• The DSFT of h(m, n) is
H(ejµ, ejν ) = H1(ejµ)H1(ejν )
1
= (1 − cos(µ)) (1 − cos(ν))
4
C. A. Bouman: Digital Image Processing - January 12, 2015 11
Example 2: Frequency Response of 2-D FIR Filter
• Plot of frequency response
jµ jν 1
H(e , e ) = (1 − cos(µ)) (1 − cos(ν))
4
jµ jν
3−D Plot of H(e ,e )
0.8
0.6
0.4
0.2
0
4
2 4
2
0
0
−2
−2
−4 −4
ν axis
µ axis
• This is a high pass filter with H(ej0, ej0) = 0
C. A. Bouman: Digital Image Processing - January 12, 2015 12
Ordering of Points in a Plane
• Recursive filter implementations require the ordering of
points in the plane.
• Let s = (s1, s2) ∈ Z 2 and r = (r1, r2) ∈ Z 2.
• Quarter plane - then s < r means:
(s2 < r2) and (s1 < r1) and s 6= r
◦ ◦ ◦
◦ ◦ ◦
◦ ◦ ×
• Symmetric half plane - then s < r means:
(s2 < r2)
◦ ◦ ◦ ◦ ◦
◦ ◦ ◦ ◦ ◦
×
• Nonsymmetric half plane - then s < r means:
(s2 < r2) or ((s2 = r2) and (s1 < r1))
◦ ◦ ◦ ◦ ◦
◦ ◦ ◦ ◦ ◦
◦ ◦ ×
C. A. Bouman: Digital Image Processing - January 12, 2015 13
2-D Infinite Impulse Response (IIR) Filters
• Difference equation
N
X N
X
y(m, n) = b(k, l)x(m − k, n − l)
k=−N l=−N
P X
X P
+ a(k, l)y(m − k, n − l)
k=−P l=1
P
X
+ a(k, 0)y(m − k, n)
k=1
Simplified notation
X X
ys = br xs−r + ar ys−r
r r>(0,0)
• For nonsymetric half plane with N = 0 and P = 2
◦ ◦ ◦ ◦ ◦
◦ ◦ ◦ ◦ ◦
◦ ◦ ×
• Number of multiplies per output point
Multiplies = (2N + 1)2 + 2(P + 1)P
| {z } | {z }
FIR Part IIR Part
C. A. Bouman: Digital Image Processing - January 12, 2015 14
2-D IIR Filter Transfer Functions
• Transfer function in Z-transform domain is
H(z1, z2) =
PN PN −k −l
k=−N l=−N b(k, l)z1 z2
PP PP −k −l
PP −k
1− k=−P l=1 a(k, l)z 1 z 2 − k=1 a(k, 0)z 1
• Transfer function in DSFT domain is
H(ejµ, ejν ) =
PN PN
−j(kµ+lν)
k=−N l=−N b(k, l)e
PP PP −j(kµ+lν)
PP
1 − k=−P l=1 a(k, l)e − k=1 a(k, 0)e−j(kµ)
C. A. Bouman: Digital Image Processing - January 12, 2015 15
Example 3: 2-D IIR Filter
• Consider the difference equation
y(m, n) = x(m, n) + ay(m − 1, n) + ay(m, n − 1)
• Spatial dependencies - ◦ previous value; × curent value
◦
◦ ×
• Taking the Z-transform of the difference equation
Y (z1, z2) = X(z1, z2) + az1−1Y (z1, z2) + az2−1Y (z1, z2)
The transfer functions is then
Y (z1, z2) 1
H(z1, z2) = =
X(z1, z2) 1 − az1−1 − az2−1
1
H(ejµ, ejν ) =
1 − ae−jµ − ae−jν
C. A. Bouman: Digital Image Processing - January 12, 2015 16
Example 3: 2-D IIR Filter in Space Domain
• For a = 1/2
1 1
y(m, n) = x(m, n) + y(m − 1, n) + y(m, n − 1)
2 2
• Looks like
1/2
1/2 ×
• Apply filter in raster scan order.
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 64 0 0 0 ⇒ 0 0 0 64 32 16 8
0 0 0 0 0 0 0 0 0 0 32 32 24 16
0 0 0 0 0 0 0 0 0 0 16 24 24 20
0 0 0 0 0 0 0 0 0 0 8 16 20 20
| {z } | {z }
Input Image Output Image
C. A. Bouman: Digital Image Processing - January 12, 2015 17
Example 3: Frequency Response of 2-D IIR Filter
• Plot of frequency response
1
H(z1, z2) =
1 − az1−1 − az2−1
for a = 0.4 .
− − −
Contour Plot of MTF for (1 − 0.4*Z11 − 0.4*Z21) 1
2
Mesh Plot of MTF for (1 − 0.4*Z−11 − 0.4*Z−21)−1
1
5
4.5
4
0
ν
3.5
2.5
2 −1
1.5
0.5 −2
4
2 4
2
0
0
−2 −3
−2
−4 −4
−3 −2 −1 0 1 2 3
ν µ
µ
C. A. Bouman: Digital Image Processing - January 12, 2015 18
Example 4: 2-D IIR Filter
• Consider the difference equation
y(m, n) = x(m, n) + ay(m − 1, n) + ay(m, n − 1)
+2ay(m + 1, n − 1)
• Spatial dependencies - ◦ previous value; × curent value
◦ ◦
◦ ×
• The transfer functions is then
1
H(z1, z2) =
1 − az1−1 − az2−1 − 2az1+1z2−1
jµ jν 1
H(e , e ) =
1 − ae−jµ − ae−jµ − 2ae+jµ−jν
C. A. Bouman: Digital Image Processing - January 12, 2015 19
Example 4: 2-D IIR Filter in Space Domain
• For a = 1/4
1 1
y(m, n) = x(m, n) + y(m − 1, n) + y(m, n − 1)
4 4
1
+ y(m + 1, n − 1)
2
• Looks like
1/4 1/2
1/4 ×
• Apply filter in raster scan order.
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
⇒
0 0 0 64 0 0 0 0 0 0 64 16 4 1
0 0 0 0 0 0 0 0 0 32 32 14 5 1 21
0 0 0 0 0 0 0 0 16 28 22 11 12 4 78 45
32}
| {z } | {z
Input Image Output Image
C. A. Bouman: Digital Image Processing - January 12, 2015 20
Example 4: Frequency Response of 2-D IIR Filter
• Plot of frequency response
1
H(z1, z2) =
1 − az1−1 − az2−1 − 2az1z2−1
for a = 0.2 .
− − − −
Contour Plot of MTF for (1 − 0.2*Z11 − 0.2*Z21 − 0.4*Z1*Z21 ) 1
2
Mesh Plot of MTF for (1 − 0.2*Z−11 − 0.2*Z−21 − 0.4*Z1*Z−21 )−1
1
5
4.5
4
0
ν
3.5
2.5
2 −1
1.5
0.5 −2
4
2 4
2
0
0
−2 −3
−2
−4 −4
−3 −2 −1 0 1 2 3
ν µ
µ
• Notice that transfer function has a diagonal orientation.
C. A. Bouman: Digital Image Processing - January 12, 2015 21
Example 5: 2-D IIR Filter
• Consider the difference equation
y(m, n) = x(m, n) + ay(m − 1, n) + ay(m, n − 1)
+ay(m + 1, n) + ay(m, n + 1)
• Spatial dependencies - ◦ previous value; × curent value
◦
◦ × ◦
◦
• Theoretically, the transfer functions is then
1
H(z1, z1) =
1 − az1−1 − az2−1 − az1 − az2
jµ jν 1
H(e , e ) =
1 − ae−jµ − ae−jµ − aejµ − aejν
• THIS DOESN’T WORK