521467S Digital Image Processing
Exercise 5.
1. A
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
B •
(a) Dilation is
A⊕B =
[
(B)a
a∈A
Result:
A⊕B
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
(b) Erosion is
A B = {z|(B)z ⊆ A}.
AB
•
•
•
2. Opening is erosion followed by dilation:
A ◦ B = (A B) ⊕ B.
Open image A with the structuring element B.
AB
•
•
•
1
•
•
•
•
Note that when there is zero in the origin of the structuring element,
the eroded image may contain 1-pixels that did not appear in the input
image!
AB⊕B
•
•
•
•
•
•
•
Now note that in dilation 1-pixels may disappear if there is zero in the
origin of structuring element.
3. Let us do gradient based edge detection using sobel masks
hx
−1 −2 −1
0
0 .
= 0
1
2
1
hy
−1 0 1
= −2 0 2 .
−1 0 1
20
20
30
f (x, y) :
40
40
40
20
22
30
37
40
40
30
30
30
30
30
30
40
37
30
25
25
25
40
40
30
22
25
27
40
40
30
22
25
20
In the following we process only such pixels that have all the needed
neighbors.
30
50
Gx = f (x, y) ∗ hx =
30
6
0
3
5
3
-30
-42
-15
5
30
0
Gy = f (x, y) ∗ hy =
-30
-40
50
3
-39
-57
-40
-66
-20
8
30
2
-21
-21
6
0
-6
-8
Now that we have the x and y components of the gradient vectors, we
move to polar representation, i.e. express the gradient as magnitude
and phase angle.
2
The gradient magnitude |G| =
42.4264
50.0000
|G(x, y)| =
42.4264
40.4475
q
50.0000
4.2426
39.3192
57.0789
G2x + G2y :
42.4264
42.0476
25.8070
21.5870
40.4475
66.0000
20.8806
11.3137
Gradient phase angle:
α=
G
Gx > 0
tan−1 Gxy ,
Gy
−1
◦
tan Gx + 180 , Gx < 0, Gy ≥ 0
G
tan−1 Gxy − 180◦ , Gx < 0, Gy < 0
90◦ ,
Gx = 0, Gy > 0
−90◦ ,
Gx = 0, Gy < 0
We get the following gradient phase angles:
45.0000
0
α(x, y)=
-45.0000
-81.4692
90.0000
45.0000
-82.6942
-86.9872
135.0000
177.2737
-125.5377
-76.6075
171.4692
180.0000
-163.3008
-45.0000
Round these to 8 directions (angle 0 is downwards, positive values to
the right), we get the following gradient orientations:
&
↓
.
←
→
&
←
←
%
↑
←
↑
↑
↑
.
To perform non-maximum suppression, go through each pixel and look
towards gradient orientation and the opposite direction. If the gradient
magnitude at either of these pixels is higher than in this pixel, set this
pixel to zero. After non-maximum suppression we have
42.4264
50.0000
G(x, y) =
42.4264
0
50.0000
0
0
57.0789
42.4264
0
25.8070
0
0
66.0000
0
11.3137
Finally let us do global thresholding of the gradient image to get the
binary edge image. Let us use threshold 40 for edges. This results in
the following binary edge image:
1
1
1
0
1
0
0
1
1
0
0
0
0
1
0
0
3
4. First let us find functions representing the probability density functions. Knowing that the area under a PDF must equal to 1, the
functions can be deduced from the figure.
For p1 (z), using area of triangle,
1
× 2 × h1 = 1
2
h1 = 1
Thus p1 (z) on the line going through points (1, 0) and (3, 1) when
1 ≤ z ≤ 3 and zero at other points. From this we get
(
p1 (z) =
1
2 (z
− 1), 1 ≤ z ≤ 3
otherwise.
0,
Then, for p2 (z), from area of rectangle
3 × h2 = 1
1
h2 =
3
and from this
(
p2 (z) =
1
3,
0,
0≤z≤3
otherwise.
The optimal threshold T can be computed from equation (10.3-10),
P1 p1 (T ) = P2 p2 (T )
Now, given that P2 = 2P1 , and assuming 1 ≤ T ≤ 3,
P1 p1 (T ) = 2P1 p2 (T )
p1 (T ) = 2p2 (T )
1
1
(T − 1) = 2 ×
2
3
7
T =
.
3
5. Split and merge procedure:
• split into four disjoint quadrants the regions Ri for which P (Ri ) =
FALSE;
• merge adjacent regions Ri and Rj for which P (Rj ∪Rk ) = TRUE;
• stop when there are no more possible splits or merges.
Segmentation procedure is described in the picture (jaa = split, yhdistä
= merge)
4
The resulting quadtree is
5
© Copyright 2026 Paperzz