German University in Cairo
Faculty of Media Engineering and Technology
Winter 2024
DMET 901 – Computer Vision
Problem Set #4 Solution
Problem 1
For the image shown below, apply an averaging filter of size 3 x 3 to the image.
0 5 10 5 1
3 10 8 20 2
6 4 7 30 5
0 200 10 20 1
Image
0 5 10 5 1
3 6 11 10 2
6 28 34 11 5
0 200 10 20 1
Output Image
German University in Cairo
Faculty of Media Engineering and Technology
Winter 2024
DMET 901 – Computer Vision
Problem Set #4 Solution
Problem 2
For each of the following filters, explain how you expect applying the filter to an
image would change the original image. Explain your reasoning.
a) b) c)
− 1 0 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0.25 0.25
− 1 0 1 0 0 0 0 0.25 0.25
a) Partial vertical edge detection.
b) No change.
c) Average filter (blur) using the lower right 2x2 kernel, introducing a bit of a shift.
German University in Cairo
Faculty of Media Engineering and Technology
Winter 2024
DMET 901 – Computer Vision
Problem Set #4 Solution
Problem 3
Given the following portion of an image and a Gaussian filter mask, show how the filter can be applied to the
central pixel of the image.
75 100 50 0 0 0.00 0.01 0.02 0.01 0.00
100 150 100 50 0 0.01 0.07 0.10 0.07 0.01
150 200 150 100 50 0.02 0.10 0.16 0.10 0.02
200 250 200 150 50 0.01 0.07 0.10 0.07 0.01
225 250 250 200 100 0.00 0.01 0.02 0.01 0.00
Image Gaussian Filter
The entries in the Gaussian filter add up to 1 – what is the significance of this? What is the effect of applying such
filter?
𝐹 ′ (2,2) = (0 ∗ 75) + (0.01 ∗ 100) + (0.02 ∗ 50) + (0.01 ∗ 0) + (0 ∗ 0) + (0.01 ∗ 100)
+ (0.07 ∗ 150) + (0.1 ∗ 100) + (0.07 ∗ 50) + (0.01 ∗ 0) + (0.02 ∗ 150)
+ (0.1 ∗ 200) + (0.16 ∗ 150) + (0.1 ∗ 100) + (0.02 ∗ 50) + (0.01 ∗ 200)
+ (0.07 ∗ 250) + (0.1 ∗ 200) + (0.07 ∗ 150) + (0.01 ∗ 50) + (0 ∗ 225)
+ (0.01 ∗ 250) + (0.02 ∗ 250) + (0.01 ∗ 200) + (0 ∗ 100) = 145
The significance of the values inside the kernel adding up to one is that both the
input and the output ranges will remain the same, 0-255 in the case of images. The
effect of the filter is blur.
German University in Cairo
Faculty of Media Engineering and Technology
Winter 2024
DMET 901 – Computer Vision
Problem Set #4 Solution
Problem 4
Consider the original image given below and its noisy version. Which of the two filters given below (h1: Average
Filter or h2: Weighted Average Filter) is better to filter out noise from the noisy image? To determine which
filter is better, use the measure S given below to find how different the filtered image obtained using each filter is
from the original image. Apply this measure to the area with pixels marked with (*).
0 20 20 0 20
20 20 20 20 20
10 10* 20* 10* 0
20 20* 20* 20* 20
20 20* 0* 20* 20
20 20* 20* 20* 20
10 0* 20* 0* 0
20 20* 20* 20* 20
10 20 10 20 10
20 20 20 20 20
Original Image Noisy Image
1 1 1 1 2 1
h1 = 1 1 1,
1
h2 = 2 4 2
1
9 16
1 1 1 1 2 1
4 4
Difference Measure: S = (F (i, j ) − O(i, j ))2 , where F is the filtered image and O is the original image.
i =2 j =2
0 20 20 0 20
10 13* 13* 12* 0
20 12* 11* 10* 20
10 12* 12* 11* 0
10 20 10 20 10
Noisy Image after applying h1
S1 = ((13-20)^2+(13-20)^2+(12-20)^2+(12-20)^2+(11-20)^2+(10-20)^2+(12-20)^2+(12-20)^2+(11-20)^2)=616
0 20 20 0 20
10 14* 14* 11* 0
20 13* 11* 11* 20
10 11* 11* 10* 0
10 20 10 20 10
Noisy Image after applying h2
S2 = ((14-20)^2+(14-20)^2+(11-20)^2+(13-20)^2+(11-20)^2+(11-20)^2+(11-20)^2+(11-20)^2+(10-20)^2)=626
As per the S measures the first filter is better.