Mathematical Morphology 297
1. Find the 3 × 3 neighborhood N
p
of p
2. Compute the matrix N
p
+ B
3. Find the maximum of that result.
We note again that since B consists of all zeros, the second and third items could be reduced
to finding the maximum of N
p
. If the neighborhood contains at least one
1
, then the output
will be
1. The output will be 0 only if the neighborhood contains all zeros.
Suppose A to be surrounded by zeros, so that neighborhoods are defined for all points
in A above. Applying these steps produces:
1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1
0 0 1 1 1 1 1 1
which again can be verified to be the dilation A ⊕ B.
If A is a grayscale image, and B is a structuring element, which will be an array of
integers, we define grayscale erosion by using the steps above; for each pixel p in the image:
1. Position B so that (0, 0) lies over p
2. Find the neighborhood N
p
of p corresponding to the shape of B
3. Find the value min(N
p
− B).
We note that there is nothing in this definition which requires B to be any particular shape
or size or that the elements of B be positive. And as for binary dilation, B does not have
to contain the origin (0, 0).
We can define this more formally; let B be a set of points with associated values. For
example, f or our square of zeros we would have:
Point
Value
(−1, −1) 0
(−1, 0)
0
(−1, 1)
0
(0, −1)
0
(0, 0)
0
(0, 1)
0
(1, −1)
0
(1, 0)
0
(1, 1)
0
The set of points forming B is called the domain of B and is denoted D
B
. Now we can
define:
(A B)(x, y) = min{A(x + s, y + t) − B(s, t), (s, t) ∈ D
B
},
(A ⊕B)(x, y) = max{A(x + s, y + t) + B(s, t), (s, t) ∈ D
B
}.
We note that some published definitions use s −x and t −y instead of x + s and y + t. This
just requires that the structuring element is rotated 180
◦
.