Mathematical Morphology 295
The results are shown in Figure 10.30. Image (a) is the result using the square structuring
element; image (b) is the result using the cross structuring element.
(a) (b)
FIGURE 10.30: Skeletonization of a binary image
10.7 A Note on the bwmorph Function in MATLAB and Octave
The theory of morphology developed so far uses versions of erosion and dilation some-
times called generalized erosion and dilation; so called because the definitions allow for
general structuring elements. This is the method used in the
imerode and imdilate func-
tions. However, the
bwmorph function actually uses a different approach to morphology;
that based on lookup tables. (Note however that Octave’s
bwmorph function implements
erosion and dilation with calls to the
imerode and imdilate functions.) We have seen the
use of lookup tables for binary operations in Chapter 11; they can be just as easily applied
to implement morphological algorithms.
The idea is simple. Consider the 3 × 3 neighborhood of a pixel. Since each pixel in the
neighborhood can only have two values, there are 2
9
= 512 different possible neighborhoods.
We define a morphological operation to be a function that maps these neighborhoods to the
values 0 and 1. Each possible neighborhood state can be associated with a numeric value
from 0 (all pixels have value 0) to 511 (all pixels have value 1). The lookup table is then a
binary vector of length 512; its k-th element is the value of the function for state k.
With this approach, we can define dilation as follows: a 0-valued pixel is changed to
1 if at least one of its eight neighbors has value 1. Conversely, we may define erosion as
changing a 1-valued pixel to 0 if at least one of its eight neighbors has value 0.
Many other operations can be defined by this method (see the help file for
bwmorph). The
advantage is that any operation can be implemented extremely easily, simply by listing the
lookup table. Moreover, the use of a lookup table allows us to satisfy certain requirements;
the skeleton, for example, can be connected and have exactly one pixel thickness. This is
not necessarily true of the algorithm presented in Section 10.6. The disadvantage of lookup
tables is that we are restricted to using 3 × 3 neighborhoods. For more details, see “Digital
Image Processing” by W. K. Pratt [35].