Mathematical Morphology 289
Python
In : b1 = np.array([[0,1,1,0],[1,1,1,1],[1,1,1,1],[0,1,1,0]])
In : b2 = ones((6,6)); b2[1:5,1:5] = 1-b1
In : tb1 = bwerode(t,b1);
In : tb2 = bwerode(1-t,b2);
In : np.where((tb1 & tb2)==1)
and this returns a coordinate of (281, 296) in MATLAB/Octave and (280, 295) in Python,
which is right in the middle of the dot. Note that eroding the text by
b1 alone is not
sufficient, as there are many places in the images where
b1 can fit. This can be seen by
viewing the image
tb1
, which is given in Figure 10.22.
FIGURE 10.22: Text eroded by a dot-shaped structuring element
10.6 Some Morphological Algorithms
In this section we shall investigate some simple algorithms that use some of the mor-
phological techniques we have discussed in previous sections.
Region Filling
Suppose in an image we have a region bounded by an 8-connected boundary, as shown
in Figure 10.23.
Given a pixel p within the region, we wish to fill up th e entire region. To do this, we start
with p, and dilate as many times as necessary with the cross-shaped structuring element
B (as used in Figure 10.6), each time taking an intersection with
A bef ore continuing. We
thus create a sequence of sets:
{p} = X
0
, X
1
, X
2
, . . . , X
k
= X
k+1
for which
X
n
= (X
n−1
⊕ B) ∩A.
Finally, X
k
∪ A is the filled region. Figure 10.24 shows how this is done.