0% found this document useful (0 votes)
4 views32 pages

Image Processing Problem Solutions

The document presents various image processing problems, including histogram analysis, mean and standard deviation calculations, and filtering techniques. It covers specific tasks such as drawing histograms, calculating specified histograms, and applying different mean filters on small images. Additionally, it discusses the adaptive median filter and zero padding in linear filtering.

Uploaded by

basmalagalalin
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views32 pages

Image Processing Problem Solutions

The document presents various image processing problems, including histogram analysis, mean and standard deviation calculations, and filtering techniques. It covers specific tasks such as drawing histograms, calculating specified histograms, and applying different mean filters on small images. Additionally, it discusses the adaptive median filter and zero padding in linear filtering.

Uploaded by

basmalagalalin
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Image processing problems

By Abdulwahab Almestekawy
Problem 1
Assume that an image of 32x32 with 32 gray levels distributed as
follows:
Gray level 12 14 15 16 18 19 20 21 22
Num of pixels 74 50 100 250 150 280 30 50 40

a) Draw the image histogram


b) Find the mean (average) intensity and the standard deviation
c) Find the equalized histogram
d) Find the specified histogram according to the following values
Zq 4 6 8 10 12 16 18 20 22
Specified Pz(Zq) 0.05 0.1 0.1 0.15 0.2 0.15 0.1 0.1 0.05
Solution r P(r)
12 0.07
a) 14 0.05
15 0.10
16 0.24
18 0.15
19 0.27
20 0.03
21 0.05
22 0.04
Solution
r P(r)
12 0.07
b) 𝐿−1 14 0.05

𝜇= 𝑟𝑖 𝑝(𝑟𝑖 ) = 12 × 0.07 + 14 × 0.05 + ⋯ + 22 × 0.04 = 17.24 15 0.10


𝑖=0 16 0.24

𝐿−1
18 0.15
19 0.27
𝜎2 = 𝑟𝑖 − 𝜇 2 𝑝 𝑟𝑖
𝑖=0 20 0.03
21 0.05
2 2 2 2
𝜎 = 12 − 17.24 × 0.07 + 14 − 17.24 × 0.05 + ⋯ + 22 − 17.24 × 0.04
22 0.04

𝜎 2 = 6.0824

𝜎= 𝜎 2 = 2.47
Solution
c)
r P(r) s s P(s)
12 0.07 2.17 2 2 0.07
14 0.05 3.72 4 4 0.05
15 0.10 6.82 7 7 0.10
16 0.24 14.26 14 14 0.24
18 0.15 18.91 19 19 0.15
19 0.27 27.28 27 27 0.27
20 0.03 28.21 28 28 0.03
21 0.05 29.76 30 30 0.05
22 0.04 31 31 31 0.04
Solution
d) P(z)
z G(z) P(z)
specified r P(r) s G(z) z
actual
4 0.05 1.55 2 12 0.07 2 2 4 0.07
6 0.10 4.65 5 14 0.05 4 5 6 0.05
8 0.10 7.75 8 15 0.10 7 8 8 0.10
10 0.15 12.4 12 16 0.24 14 12 10 0.24
12 0.20 18.6 19 18 0.15 19 19 12 0.15
16 0.15 23.25 23 19 0.27 27 26 18 0.27
18 0.10 26.35 26 20 0.03 28 29 20
0.08
20 0.10 29.45 29 21 0.05 30 29 20
22 0.05 31 31 22 0.04 31 31 22 0.04
Problem 2
The image given below is a 3x3, what will the value of the center pixel
change to when this image is passed through:
a) Arithmetic mean filter
1 7 5
b) Geometric mean filter 6 2 3
c) Harmonic mean filter 1 4 2
Solution
a) Arithmetic mean filter:
(1/9) * (1 + 7 + 5 + 6 + 2 + 3 + 1 + 4 + 2) = 3.44
1 7 5
b) Geometric mean filter
6 2 3
(1*7*5*6*2*3*1*4*2)^(1/9) = 2.79
1 4 2
c) Harmonic mean filter
9/( (1/1) + (1/7) + (1/5) + (1/6) + (1/2) + (1/3) + (1/1) + (1/4) + (1/2) )
= 2.20
Also remember
Problem 3
Given an input image of size 7x7 shown below, was filtered using 3x3
adaptive median filter with maximum allowed size of 5x5. What are the
values of pixels x, y, and z in the output image?

3 3 4 3 3 3 0
3 0 0 0 0 0 3
3 4 0 0 4 4 3 z
Adaptive median x
4 5 7 7 0 0 3 filter
3 3 6 0 0 7 0 y

3 0 4 3 3 5 3
3 4 3 3 0 0 4
Adaptive median filter algorithm
Sorted pixels: [0, 0, 0, 3, 4, 5,
6, 7, 7]
Solution Stage A: z
x
Zmed = 4
To find x: Zmin = 0
y

Zmax = 7
A1 = Zmed – Zmin = 4
3 3 4 3 3 3 0 A2 = Zmed – Zmax = -3
3 0 0 0 0 0 3
A1 > 0 and A2 < 0? Yes Answer:
3 4 0 0 4 4 3 x=4
4 5 7 7 0 0 3 Statge B:

3 3 6 0 0 7 0 Zxy = 7
3 0 4 3 3 5 3 B1 = Zxy – Zmin = 7
B2 = Zxy – Zmax = 0
3 4 3 3 0 0 4
B1 > 0 and B2 < 0? No

output Zmed
x=4
Sorted pixels: [0, 0, 0, 3, 3, 4,
6, 7, 7]
Solution Stage A: z
x
Zmed = 3
To find y: Zmin = 0
y

Zmax = 7
A1 = Zmed – Zmin = 3
3 3 4 3 3 3 0 A2 = Zmed – Zmax = -4
3 0 0 0 0 0 3
A1 > 0 and A2 < 0? Yes Answer:
3 4 0 0 4 4 3 x=4
4 5 7 7 0 0 3 Statge B: y=3
3 3 6 0 0 7 0 Zxy = 0
3 0 4 3 3 5 3 B1 = Zxy – Zmin = 0
B2 = Zxy – Zmax = -7
3 4 3 3 0 0 4
B1 > 0 and B2 < 0? No

output Zmed
y=3
Sorted pixels: [0, 0, 0, 0, 0, 4,
5, 7, 7]
Solution Stage A: z
x
Zmed = 0
To find z: Zmin = 0
y

Zmax = 7
A1 = Zmed – Zmin = 0
3 3 4 3 3 3 0 A2 = Zmed – Zmax = -7
3 0 0 0 0 0 3
A1 > 0 and A2 < 0? No Answer:
3 4 0 0 4 4 3 x=4
4 5 7 7 0 0 3 Increase window size y=3
3 3 6 0 0 7 0
3 0 4 3 3 5 3
3 4 3 3 0 0 4
Sorted pixels: [0, 0, 0, 0, 0, 0,
0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 4,
Solution 4, 4, 4, 5, 6, 7, 7]
z
Stage A: x
To find z: Zmed = 3
y

Zmin = 0
Zmax = 7
3 3 4 3 3 3 0 A1 = Zmed – Zmin = 3
3 0 0 0 0 0 3 A2 = Zmed – Zmax = -4
Answer:
3 4 0 0 4 4 3 A1 > 0 and A2 < 0? Yes x=4
4 5 7 7 0 0 3 y=3
Stage B: z=3
3 3 6 0 0 7 0
3 0 4 3 3 5 3 Zxy = 0
B1 = Zxy – Zmin = 0
3 4 3 3 0 0 4 B2 = Zxy – Zmax = -7

B1 > 0 and B2 < 0? No


Output Zmed
z=3
Also remember
Problem 4
Using the figure to the right, find the filtered image using zero padding
of the original image.

Shift-invariant
Linear-filter 1:
2 9 10 0 ? ? ? ?
7 1 6 1 0 1 0 ? ? ? ?
10 15 2 6 1/4 1 0 1 ? ? ? ?
11 3 8 10 0 1 0 ? ? ? ?

Original image Filtered image 1


Solution
0 0 0 0 0 0 Shift-invariant
0 2 9 10 0 0 Linear-filter 1: ? ? ? ?
0 7 1 6 1 0 0 1 0 ? ? ? ?
0 10 15 2 6 0 1/4 1 0 1 ? ? ? ?
0 11 3 8 10 0 0 1 0 ? ? ? ?
0 0 0 0 0 0

Original image Filtered image 1


(with padding) (with padding)
Solution
0 0 0 0 0 0 Shift-invariant
0 2 9 10 0 0 Linear-filter 1: 4 ? ? ?
0 7 1 6 1 0 0 1 0 ? ? ? ?
0 10 15 2 6 0 1/4 1 0 1 ? ? ? ?
0 11 3 8 10 0 0 1 0 ? ? ? ?
0 0 0 0 0 0

Original image Filtered image 1


(with padding) (with padding)

new value = 0 *0 + 1/4*0 + 0 *0


+1/4*0 + 0 *2 + 1/4*9
+0 *0 + 1/4*7 + 0 *1
= 4
Solution
0 0 0 0 0 0 Shift-invariant
0 2 9 10 0 0 Linear-filter 1: 4 3.25 ? ?
0 7 1 6 1 0 0 1 0 ? ? ? ?
0 10 15 2 6 0 1/4 1 0 1 ? ? ? ?
0 11 3 8 10 0 0 1 0 ? ? ? ?
0 0 0 0 0 0

Original image Filtered image 1


(with padding) (with padding)

new value = 0 *0 + 1/4*0 + 0 *0


+1/4*2 + 0 *9 + 1/4*10
+0 *7 + 1/4*1 + 0 *6
= 3.25
Solution
0 0 0 0 0 0 Shift-invariant
0 2 9 10 0 0 Linear-filter 1: 4 3.25 3.75 ?
0 7 1 6 1 0 0 1 0 ? ? ? ?
0 10 15 2 6 0 1/4 1 0 1 ? ? ? ?
0 11 3 8 10 0 0 1 0 ? ? ? ?
0 0 0 0 0 0

Original image Filtered image 1


(with padding) (with padding)

new value = 0 *0 + 1/4*0 + 0 *0


+1/4*9 + 0 *10 + 1/4*0
+0 *1 + 1/4*6 + 0 *1
= 3.75
Solution
0 0 0 0 0 0 Shift-invariant
0 2 9 10 0 0 Linear-filter 1: 4 3.25 3.75 2.75
0 7 1 6 1 0 0 1 0 ? ? ? ?
0 10 15 2 6 0 1/4 1 0 1 ? ? ? ?
0 11 3 8 10 0 0 1 0 ? ? ? ?
0 0 0 0 0 0

Original image Filtered image 1


(with padding) (with padding)

new value = 0 *0 + 1/4*0 + 0 *0


+1/4*10 + 0 *0 + 1/4*0
+0 *6 + 1/4*1 + 0 *0
= 2.75
Solution
0 0 0 0 0 0 Shift-invariant
0 2 9 10 0 0 Linear-filter 1: 4 3.25 3.75 2.75
0 7 1 6 1 0 0 1 0 3.25 ? ? ?
0 10 15 2 6 0 1/4 1 0 1 ? ? ? ?
0 11 3 8 10 0 0 1 0 ? ? ? ?
0 0 0 0 0 0

Original image Filtered image 1


(with padding) (with padding)

new value = 0 *0 + 1/4*2 + 0 *9


+1/4*0 + 0 *7 + 1/4*1
+0 *0 + 1/4*10 + 0 *15
= 3.25
Solution
0 0 0 0 0 0 Shift-invariant
0 2 9 10 0 0 Linear-filter 1: 4 3.25 3.75 2.75
0 7 1 6 1 0 0 1 0 3.25 9.25 ? ?
0 10 15 2 6 0 1/4 1 0 1 ? ? ? ?
0 11 3 8 10 0 0 1 0 ? ? ? ?
0 0 0 0 0 0

Original image Filtered image 1


(with padding) (with padding)

new value = 0 *2 + 1/4*9 + 0 *10


+1/4*7 + 0 *1 + 1/4*6
+0 *10 + 1/4*15 + 0 *2
= 9.25
Solution
0 0 0 0 0 0 Shift-invariant
0 2 9 10 0 0 Linear-filter 1: 4 3.25 3.75 2.75
0 7 1 6 1 0 0 1 0 3.25 9.25 3.5 3
0 10 15 2 6 0 1/4 1 0 1 8.25 4 8.75 3.25
0 11 3 8 10 0 0 1 0 3.25 8.5 3.75 3.5
0 0 0 0 0 0

Original image Filtered image 1


(with padding) (with padding)
Solution
0 0 0 0 0 0 Shift-invariant
0 2 9 10 0 0 Linear-filter 1: 4 3.25 3.75 2.75
0 7 1 6 1 0 0 1 0 3.25 9.25 3.5 3
0 10 15 2 6 0 1/4 1 0 1 8.25 4 8.75 3.25
0 11 3 8 10 0 0 1 0 3.25 8.5 3.75 3.5
0 0 0 0 0 0
Filtered image 1
Original image
(with padding)
Problem 5
Calculate F(0, 0) for the following image:
1 6 1
15 2 6
3 8 10
Answer
𝑀−1 𝑁−1
x\y 0 1 2 𝑢𝑥 𝑣𝑦
−𝑗2𝜋 𝑀 + 𝑁
0 1 6 1 𝐹 𝑢, 𝑣 = 𝑓 𝑥, 𝑦 𝑒
1 15 2 6 𝑥=0 𝑦=0
2 3 8 10
𝑀−1 𝑁−1
M = height = 3
N = width = 3 𝐹 0, 0 = 𝑓 𝑥, 𝑦
𝑥=0 𝑦=0

F(0, 0) = 1 + 6 + 1 + 15 + 2 + 6 + 3 + 8 + 10 = 52
Problem 6
Calculate F(1, 1) for the following image:
1 6 1
15 2 6
3 8 10
Answer
𝑀−1 𝑁−1
x\y 0 1 2 𝑢𝑥 𝑣𝑦
−𝑗2𝜋 𝑀 + 𝑁
0 1 6 1 𝐹 𝑢, 𝑣 = 𝑓 𝑥, 𝑦 𝑒
1 15 2 6 𝑥=0 𝑦=0
2 3 8 10
𝑀−1 𝑁−1
M = height = 3 𝑥 𝑦
−𝑗2𝜋 𝑀+𝑁
N = width = 3 𝐹 1, 1 = 𝑓 𝑥, 𝑦 𝑒
𝑥=0 𝑦=0

F(1, 1) = 1 + 6*e^(-j2π/3) + 1*e^(-j4π/3) + 15*e^(-j2π/3) + 2*e^(-j4π/3) + … + 10*e^(-j8π/3)


Answer: Simplification of result (OPTIONAL)
F(1, 1) = 1 + 6*e^(-j2π/3) + 1*e^(-j4π/3) + 15*e^(-j2π/3) + 2*e^(-j4π/3) + … + 10*e^(-j8π/3)

To convert (𝑟 𝑒 𝑗𝜃 ) to the form (A + j B) we use the following equations:


𝐴 = 𝑟 cos 𝜃
𝐵 = 𝑟 sin 𝜃
For example:

6*e^(-j2π/3) = 6 cos(-2π/3) + j 6 sin(-2π/3) = -3 – j 3√(3)

Do the same for all terms…

Put the final answer in the form: 𝑅(𝑢, 𝑣) + 𝑗 𝐼(𝑢, 𝑣)


Note
Fourier (or frequency) spectrum:
𝐹(𝑢, 𝑣) = 𝑅2 𝑢, 𝑣 + 𝐼2 (𝑢, 𝑣)
Phase angle:
𝐼 2 (𝑢, 𝑣)
𝜙 𝑢, 𝑣 = tan−1 2
𝑅 𝑢, 𝑣

You might also like