You are on page 1of 6

521467S Digital Image Processing

Solutions to Exercise 2.
1. (a) Zero padding of the borders:
0
0
0
0
0
0

0
1
5
1
2
0

0
2
2
1
4
0

0
4
5
3
6
0

0
5
2
6
7
0

0
0
0
0
0
0

The value of the processed pixel is replaced by the average of the


pixel values in the window. The corresponding convolution mask
is

1 1 1
1

wa = 1 1 1 .
9
1 1 1
All the pixels are scanned from left to right and from up to down.
The added zero pixels on the borders are not processed.
g(0, 0) = 1/9 (0 + 0 + 0 + 0 + 1 + 2 + 0 + 5 + 2)
= 10/9 = 1.111 . . . 1
g(0, 1) = 1/9 (0 + 0 + 0 + 1 + 2 + 4 + 5 + 2 + 5)
= 19/9 = 2.111 . . . 2
..
.
The resulting filtered image:
1
1
2
1

2
3
3
2

2
3
4
3

(b) The pixels of the zero padded image


now using mask

1 2
1
wb =
2 4
16
1 2

2
3
3
2
are scanned as in part (a),

2 .
1

g(0, 0) = 1/16 (1 0 + 2 0 + 1 0 + 2 0 + 4 1
+2 2 + 1 0 + 2 5 + 1 2)
= 20/16 = 1.25 1
1

g(0, 1) = 1/16 (1 0 + 2 0 + 1 0 + 2 1 + 4 2
+2 4 + 1 5 + 2 2 + 1 5)
= 32/16 = 2
..
.
The resulting filtered image:
1
2
2
1

2
3
3
2

3
4
4
4

2
3
4
3

Both the averaging filters have a blurring effect on the image.


The blurring effect increases when the mask size increases. As
the noise reduces also the local contrast becomes worse.
(c) Only those pixels are processed that have all the needed neighbors:
1
5
1
2

2
2
1
4

4
5
3
6

5
2
6
7

The value for central pixel in the output image is obtained


by selecting the median (the middle one when the values are
in increasing order) of the values under the mask.
Noise is reduced but the local contrast remains better. Thin
lines are however lost.
Reduces effectively impulsive noise.
g(0, 0) = median(1, 2, 4, 5, 2, 5, 1, 1, 3)
= median(1, 1, 1, 2, 2, 3, 4, 5, 5) = 2
g(0, 1) = median(2, 4, 5, 2, 5, 2, 1, 3, 6)
= median(1, 2, 2, 2, 3, 4, 5, 5, 6) = 3
..
.
The resulting median filtered image:
2
3

3
4

Note that the resulting image is smaller than the input image due
to the selected border handling.
(d) Reflecting the border pixels

1
1
5
1
2
2

1
1
5
1
2
2

2
2
2
1
4
4

4
4
5
3
6
6

5
5
2
6
7
7

5
5
2
6
7
7

The pixels of the this image are scanned using mask

0 1 0

wd = 1 4 1 .
0 1 0
g(0, 0) = 0 1 + 1 1 + 0 2 + 1 1 4 1 + 1 2 +
05+15+02=5
g(0, 1) = 0 1 + 1 2 + 0 4 + 1 1 4 2 + 1 4 +
05+12+05=1
..
.
The resulting image:
5
-11
5
1

1
5
6
-3

0
-9
6
-4

-4
10
-6
-2

2. (a) The 2-dimensional Fourier transform is


1 N
1
X
1 MX
f (x, y)ej2(ux/M +vy/N )
F (u, v) =
M N x=0 y=0

In our case, M = N = 4, so we get


F (u, v) =

3 X
3
1 X
f (x, y)ej2(ux/4+vy/4) ,
16 x=0 y=0

0 u 3, 0 v 3
and
F (0, 0) =
=
F (0, 1) =

3 X
3
1 X
f (x, y)ej2(0x/4+0y/4)
16 x=0 y=0

1
(1 + 0 + 0 + 0 + . . . + 2 + 1) = 4/16
16
3 X
3
1 X
f (x, y)ej2(0x/4+1y/4)
16 x=0 y=0
3

1
(1ej210/4 + 2ej212/4 + 1ej212/4
16
1
2
(1 + 2(1) + 1(1)) =
16
16

=
=
..
.

3 X
3
1 X
f (x, y)ej2(1x/4+3y/4)
16 x=0 y=0

F (1, 3) =

1
(1ej2(10/4+30/4) + 2ej2(11/4+32/4)
16
+1ej2(12/4+32/4) )
1
1 1
=
(1 + 2j + 1) = + j
16
8 8
..
.

Resulting frequency domain image F (u, v)

F (u, v) =

2
1
2
1
j 1 + j j 1 + j
0
1
0
1
j 1j j 1j

(b) Separability of the 2-D Fourier transform means that we can get
the full 2-D transform by applying 1-D transform twice. First
we apply the 1-D transform to rows and then to columns of the
image (or vice versa).
Let us compute an intermediate image F (x, v) by applying 1-D
DFT to rows of the input image f (x, y)
1
1 NX
F (x, v) =
f (x, y)ej2vy/N .
N y=0

In our case the number of columns N = 4 so we get


F (x, v) =

3
1X
f (x, y)ej2vy/4 , 0 x 3, 0 v 3
4 y=0

F (0, 0) =

3
1X
1
f (0, y)ej20y/4 = (1 + 0 + 0 + 0)
4 y=0
4

..
.
F (1, 3) =
=

3
1X
f (1, y)ej23y/4
4 y=0

1 j230/4
(0e
+ 0ej231/4 + 2ej232/4
4
4

+0ej233/4 =

1
2

..
.
The resulting intermediate image F (x, v):

F (x, v) =
4

1 1 1 1
2 2 2 2

1 1 1 1
0 0 0 0

Next we need to do 1-D DFT to columns of the intermediate


image:
1
1 MX
F (x, v)ej2ux/M
F (u, v) =
M x=0
and as M = 4
F (u, v) =

3
1X
F (x, v)ej2ux/4 , 0 u 3, 0 v 3
4 x=0

F (0, 0) =

3
1X
1 1
F (x, 0)ej20x/4 = (1 + 2 + 1 + 0) = 4/16
4 x=0
4 4

..
.
F (1, 3) =

3
1X
1 1
F (x, 3)ej21x/4 = (1ej210/4 +
4 x=0
4 4

(2)ej211/4 + (1)ej212/4 + 0ej213/4 )


1
1 1
=
(1 + (2)(j) + (1)(1)) = + j
16
8 8
..
.
Resulting frequency domain image F (u, v)

F (u, v) =

2
1
2
1
j 1 + j j 1 + j
0
1
0
1
j 1j j 1j

3. Image filtering in frequency space is done by element-wise multiplication of the frequcency domain represenations of the image and the
filter.
G(u, v) = F (u, v)H(u, v)

2
1
2
1
j 1 + j j 1 + j
0
1
0
1
j 1j j 1j

32

1


4

2
0
0
0

1
0
0
0

4 1 0 1
0 0 0 0

0 0 0 0
0 0 0 0

The filtered image is obtained through inverse DFT,


g(x, y) =

1
M
1 N
X
X

G(u, v)ej2(ux/M +vy/N )

u=0 v=0

16

1
1
1
1

2
2
2
2

3
3
3
3

2
2
2
2

0
0
0
0

1
0
0
0

You might also like