Page 146 -
P. 146
120 Chapter 3 ■ Digital Morphology
method, first discussed by Levialdi, uses six different structuring elements.
The first four elements are used to erode the image, and were carefully chosen
so as not to change the connectivity of the regions being eroded. The last two
elements are used to count isolated ‘‘1’’ pixels; in MAX this is done using the
# operator, and so these structuring elements will not be needed.
Figure 3.22 shows the four structuring elements, named L1 through L4. The
initial count of regions is the number of isolated pixels in the input image A,
and the image of iteration 0 is A:
count 0 = #A
(EQ 3.27)
A 0 = A
(a) (b) (c) (d) (e)
Figure 3.22: Counting 8-connected regions. (a)–(d) The structuring elements L1 through
L4. (e) An example image having eight regions. The algorithm counts these correctly.
The image of the next iteration is the union of the four erosions of the current
image:
A n+1 = (A n L 1 ) ∪ (A n L 2 ) ∪ (A n L 3 ) ∪ (A n L 4 ) (EQ 3.28)
And the count for that iteration is the number of isolated pixels in that
image:
count n+1 = #A n+1 (EQ 3.29)
The iteration stops when A n becomes empty (all 0 pixels). The overall
number of regions is the sum of all the values count i . The MAX program that
does this is:
// Count 8-connected regions.
image L1, L2, L3, L4, a, b;
int count;
begin
L1 := {[2,2], [0,1], ˝ 0101˝};
L2 := {[2,2], [0,1], ˝ 0110˝};
L3 := {[2,2], [0,1], ˝ 1001˝};
L4 := {[2,2], [0,1], ˝ 1100˝};
do a << “$1“;