8
.x<H 1'21 .St'N lid ), August 1994 Pattern Recognition Letters 15 (1994) 825-832 Pattern Recognition Letters A one-pass thinning algorithm with interference guards Alan Stewart Department of Computer Science, The Queen's University of Belfast, BelJitstBT7 INN. :Vorthern Ireland, United Kmgdom Received 7 January 1994 Abstract A fully parallel thinning algorithm may be considered to be constructed in two stages: (i) the definition of edge pixels which can be sequentially removed; and (ii) the definition of protection guards which ensures that the parallel thinning of pixels does not involve destructive interference - for example, the complete removal of a pattern. The goal of this article is to modify the protection conditions of Wu and Tsai's algorithm ( 1992 ) and to prove that the resulting method is free from undesirable parallel interactions. Keywords: Thinning algorithms; Binary images; Parallel interference guards 1. Introduction The application of a correct thinning algorithm to a binary image results in a new image which is a skel- eton of unitary thickness of the original pattern. A pattern is assumed to be made of black pixels (iden- tified with the logical constant true). One method of defining a thinning algorithm is to peel off the outer layer of a pattern until a skeleton remains. A parallel algorithm is such that subsets of pixels of the image may be processed "simultaneously". However, it is necessary to ensure that such parallel processing does not result in unwanted interference: the pattern should not be either completely erased or its connec- tivity altered. Destructive interference may be avoided in one of three ways: (i) A multiple-pass algorithm may be defined which has a different directional bias in each of its sub-iterations. For example, Zhang and Suen's algo- rithm (1984) removes south and east boundary ele- ments on the first pass and, provided a unitary skel- eton has not been computed, removes north and west boundary elements on the second pass. (ii) A grid may be partitioned into disjoint sets of pixels where the computations of the elements of each of the sets are independent. Each set may be pro- cessed in parallel in a sub-iteration. For example, Olszewski's algorithm (1992) partitions a grid into four sets depending on the (x, y) Cartesian co-ordi- nate position ofa pixel (x odd and y odd, x odd and y even, x even and y odd and, finally, x even and y even ). (iii) A one-pass algorithm may be defined which "protects" certain patterns thus preventing the obli- teration of patterns or alterations in connectivity. For example, Holt's algorithm protects lines of thickness two and isolated two by two squares. Pixels may be classified according to whether or not they are: (i) on the edge of a pattern; (ii) on an isolated edge which connects two re- gions; and (iii) on the end point of a skeleton. 0167-8655/94/$07.00 © 1994 Elsevier Science B.V. All rights reserved SSD10167-8655 (94)00009-R

A one-pass thinning algorithm with interference guards

Embed Size (px)

Citation preview

Page 1: A one-pass thinning algorithm with interference guards

.x<H

1'21 .St 'N l i d ),

August 1994

Pattern Recognition Letters 15 (1994) 825-832

Pattern Recognition Letters

A one-pass thinning algorithm with interference guards

Alan Stewart Department of Computer Science, The Queen's University of Belfast, BelJitst BT7 INN. :Vorthern Ireland, United Kmgdom

Received 7 January 1994

Abstract

A fully parallel thinning algorithm may be considered to be constructed in two stages: (i) the definition of edge pixels which can be sequentially removed; and (ii) the definition of protection guards which ensures that the parallel thinning of pixels does not involve destructive interference - for example, the complete removal of a pattern. The goal of this article is to modify the protection conditions of Wu and Tsai's algorithm ( 1992 ) and to prove that the resulting method is free from undesirable parallel interactions.

Keywords: Thinning algorithms; Binary images; Parallel interference guards

1. Introduction

The appl ica t ion of a correct thinning algori thm to a binary image results in a new image which is a skel- eton of uni tary thickness of the original pattern. A pat tern is assumed to be made of black pixels ( iden- tified with the logical constant t rue) . One method of defining a thinning algori thm is to peel off the outer layer of a pat tern until a skeleton remains. A parallel algori thm is such that subsets of pixels of the image may be processed "s imul taneously" . However, it is necessary to ensure that such parallel processing does not result in unwanted interference: the pat tern should not be ei ther completely erased or its connec- t ivi ty altered. Destruct ive interference may be avoided in one of three ways:

( i ) A mult iple-pass algori thm may be defined which has a different di rect ional bias in each of its sub-i terations. For example, Zhang and Suen's algo- r i thm (1984) removes south and east boundary ele- ments on the first pass and, provided a uni tary skel-

eton has not been computed, removes north and west boundary elements on the second pass.

( i i ) A grid may be par t i t ioned into disjoint sets of pixels where the computat ions of the elements of each of the sets are independent . Each set may be pro- cessed in parallel in a sub-iteration. For example, Olszewski 's algori thm (1992) par t i t ions a grid into four sets depending on the (x, y) Cartesian co-ordi- nate posi t ion o f a pixel (x odd and y odd, x odd and y even, x even and y odd and, finally, x even and y even ).

( i i i ) A one-pass algorithm may be defined which "protec ts" certain pat terns thus preventing the obli- teration of patterns or alterations in connectivity. For example, Holt 's algori thm protects lines of thickness two and isolated two by two squares.

Pixels may be classified according to whether or not they are:

( i ) on the edge of a pattern; ( i i ) on an isolated edge which connects two re-

gions; and ( i i i ) on the end point of a skeleton.

0167-8655/94/$07.00 © 1994 Elsevier Science B.V. All rights reserved SSD10167-8655 (94)00009-R

Page 2: A one-pass thinning algorithm with interference guards

826 A. Stewart/Pattern Recognition Letters 15 (1994) 825-832

Certain edge pixels may be further classified as (iv) "protected" in order to avoid the simultaneous re- moval of certain pixel patterns. A parallel algorithm should remove those pixels which satisfy condition (i) but fail conditions (ii), (iii) and (iv).

Traditionally, a pixel which is on a non-connecting edge which is not a skeletal end-point is identified with the condition that it has between 2 and 6 con- nected neighbours where connectedness is defined as the existence of a four-connected path (horizontal and vertical links only) between any two neighbours which are present (Hilditch, 1969; Holt et al., 1987). However, there are patterns such as

0 0 0 0

1 1 1 0

0 0 1 0

0 0 1 0

which are invariant under this definition but which should be further "cleaned". Furthermore, the pattern

1 0 0

1 1 0

0 1 0

0 0 0

is such that skeletal end points can be repeatedly re- moved! The one-pass algorithm of Wu and Tsai de- fines a set of 8- and 4-connected removal conditions which avoids both of these problems. However, the removal conditions,

x 0 0 x 1 1

1 c 0 0 c 1

x 1 x 0 0 x

(e) (f)

x l x 0 0 x

1 c 0 0 c 1

x 0 0 x 1 1

(h) (i)

where c denotes a central pixel which is present and which may be removed and x denotes an arbitrary pixel (either 1 or 0), are such that an isolated two by two square is not protected (the templates (e), (f), (h) and (i) may result in the parallel removal of the four corners of an isolated square). It is vital that a parallel one-pass thinning algorithm is guaranteed to

preserve connectivity and protect isolated regions from being completely removed. The aim of this ar- ticle is to present a one-pass thinning algorithm which protects isolated regions, isolated connectors and skeletal end points, avoids severe erosion but which removes as many other edge elements as is prudent.

2. The Euler characteristic

The notion of Euler characteristic (Olszewski, 1992) may be used to define the set of edge pixels which are not isolated connectors between two re- gions. Consider a square representation of a 3 X 3 window which includes vertices, edges and pixels as shown in Fig. 1. For example, the central pixel with its surrounding 3 X 3 window includes 5 black pixels (P), 16 edges of black pixels (E) and 12 vertices of black pixels V). The Euler characteristic C is de- fined by:

C= V - E + P

If the characteristic ofa 3 X 3 window which includes a central pixel is the same as the characteristic of the same window without the central pixel then the pixel is an edge pixel which is not a connector. For exam- ple, the characteristic of the pattern in Fig. 1 is 1. However, the characteristic of the pattern in Fig. 2 is 2. Therefore, in this case, the central pixel should not be removed by a thinning procedure. An efficient way of determining whether or not the Euler characteris- tic is preserved after the removal of the central pixel is to derive the Boolean condition K - L = 1 where K is the number of white pixels that are not in the cor- ners of the window and L is the number of white pix- els in the corners with two white neighbours

Fig. 1.

Page 3: A one-pass thinning algorithm with interference guards

A. Stewart/Pattern Recognition Letters 15 (I 994) 825-832 827

Fig. 2.

(Olszewski. 1992). However, the concept of preser- vation of the Euler characteristic in isolation results in the removal of skeletal end points. The definition of Euler characteristic may be used to define an edge element (for a sequential computation). One such definition of edge is given in the next section.

3. A correct o n e - p a s s t h i n n i n g a l g o r i t h m

The following templates (and any 90 degree rota- tion ot" them) are such that the central element is guaranteed to be an edge element which is not a con- nectornoraskeletalendpoint :

1 0 0 l l x x 0 0

l c 0 l c 0 l c 0

1 0 0 l l x x l x

templalc 1 template 2 lo~lplate 3

The first pattern removes surface noise. The second pattern allows the thinning of east edges and the third pattern allows the 8-connected thinning of parallel diagonal lines (Wu and Tsai, 1992) (when SW is 0). Template 2 extends the notion of edge defined by Wu and Tsai ( 1992 ) to include central pixels which have 7 connected neighbours and a missing side neighbour (Holt et al., 1987 ). The third pattern differs from the 4-connected edge definition in Holt's algorithm in that the SW element may be absent. The Euler char- acteristic is preserved after the removal of the central pixel for all of these patterns.

All three of the templates have the middle line as a common sub-pattern. Thus, a corresponding Boo- lean condition is:

c . ( W . ( - E ) ) . ( N W . S W )

. ( ( N + ( - N E ) ) - ( S + ( - S E ) ) )

+ ( S . - ( N + N E ) ) . (1)

Three 90 rotations of the templates can be generated in a similar way. The edge condition is then the OR combination of the three rotations, i.e., 60 logical op- erations (see Table 1 ).

It is not possible for a correct parallel method to simultaneously remove all such edge elements: such removal could cause the complete eradication of pat- terns or an alteration in connectivity. Therefore, an additional protection condition is defined which may result in the preservation of"critical edge" elements. The protection conditions may be built into the def- inition of edge (Wu and Tsai, 1992); alternatively, the protection conditions can be explicitly derived. The latter approach has the advantages of (i) sepa- rating concerns and (ii) providing algorithms which are efficient to implement directly on parallel hardware.

A scheme which ensures the preservation of con- nectivity and avoids the complete removal of any patterns is outlined below. Protection conditions are devised for each of the templates in turn:

T e m p l a t e 1. The pattern

1 0 0

1 c 0

1 0 0

is such that W cannot be removed (template defini- tions). Therefore, connectivity can not be affected by removal of c and the entire pattern cannot be removed.

T e m p l a t e 2. The pattern

1 1 x

1 c 0 ( T 2 )

1 1 x

is such that N cannot be removed if NE is present and S cannot be removed if SE is present - by the definition of the edge templates. Thus, connectivity

Page 4: A one-pass thinning algorithm with interference guards

828

Table 1 The edge function

A. Stewart/Pattern Recognition Letters 15 (1994) 825-832

edge (NW, N, NE, W, c, E, SW, S, SE) = c . ( ( W . ( - E ) ) . (((NW.SW). ( ( N + ( - N E ) ) . (S+ ( - S E ) ) ) ) + ( S . - ( N + N E ) ) ) +

( N . ( - S ) ) - ( ( ( N W . N E ) . ( (E+ ( - S E ) ) - ( W + ( - S W ) ) ) ) + ( W . - (E+SE) ) ) + ( E . ( - W ) ) . ( ( ( N E . S E ) . ( (S+ ( - S W ) ) . (N+ ( - N W ) ) ) ) + ( N . - (S+SW)) ) + ( S . ( - N ) ) . ( ( ( S W S E ) . ( ( W + ( - N W ) ) . ( E + ( - N E ) ) ) ) + ( E . - ( W + N W ) ) ) )

cannot be broken by the removal of the central ver- tical line. However, it is necessary to ensure that W and c are not simultaneously removed. Thus, an ele- ment (W) is protected if:

edge(c) .N.S.edge (E) . (2)

The condition identifies uniquely pixels satisfying template 2. In practice the condition has the effect of protecting one edge (the west) of parallel vertical lines. Although the condition has a directional bias (west over east) it also ensures the preservation of connectivity ofa 180-degree rotation of the template:

x 1 1

0 c 1

x 1 1

In this case the central element is protected and con- nectivity cannot be broken. In a similar way 90-de- gree rotations can be protected by the condition

edge(c ).edge(S ) .W.E. ( 3 )

Finally, it is necessary to ensure that the entire pat- tern (T2) cannot be removed. If either NE or SE is present then the pattern must contain a non-edge ele- ment. Otherwise, the pattern can be guarded against total removal by the condition

edge(c) .edge(E).edge(S).edge (SE). (4)

In practice this condition protects the NW corner of an isolated 2 × 2 square. It should be noted that con- dition (4) cannot cause interference which would breakdown connectivity. For example, the pattern

e e 1 ... e e 9

where e denotes an edge element, is such that the left- most e is protected by condition (4) but the right- most e is additionally protected by condition (3). Thus, connectivity is preserved. The pattern

e e 0 ...

e 1 1 ...

is such that the central lower element cannot be an edge element and, again connectivity must be preserved.

T e m p l a t e 3. The instant of template 3 where SW is 1

x 0 0

1 c 0

1 1 x

is such that if the NW element is a 1 then it is not possible for the W element to be on an edge (by the definition of the edge templates). Therefore, as c and W cannot be simultaneously removed connectivity cannot be broken along the central horizontal axis. Similarly, if the SE element is a 1 then the S element is not on an edge and connectivity through the cen- tral vertical axis is ensured. Thus, connectivity can- not be broken by the removal of the central element. Similar arguments apply to the three rotations of this pattern.

The argument above is not valid for the instant of template 3 where the SW element is absent:

x 0 0

1 c 0

0 1 x

In this case NW may be present and W may be an edge element. In order to avoid the complete re- moval of the central horizontal or vertical lines it is necessary to add the protection condition

edge(c).( - S W ) ' S ' W

. ((edge(S) .SE) + (edge ( W . N W ) ) .

The first 4 terms uniquely identify this template; the latter terms ensure c is protected as infrequently as it

Page 5: A one-pass thinning algorithm with interference guards

A. Stewart / Pattern Recognition Letters 15 (1994) 825 -832 829

is possible to do so. The expression may be simplified to:

4. O t h e r Euler character i s t i c preserv ing edge

t e m p l a t e s

e d g e ( c ) . ( - SW).S.W. (edge(S) + edge(W) ) (5)

as edge(S)~SE, etc. In practice this condition pro- tects one side of a bottom right to top left diagonal line of thickness two and approximately corresponds to the various definitions of diagonal edge in (Wu and Tsai, 1992). The condition addition protects the connectivity &the rotation:

x 1 0

0 c 1

0 0 x

Here the N and E elements are protected if they are edge elements (and NW and SE are present respec- tively) by condition (5). In a similar way a bottom left to top right diagonal line of thickness two can be protected by the condition:

edge(c). ( - SE).S.E. (edge(S) +edge(E) ) (6)

This ensures that connectivity of all rotations is protected.

Finally, the entire pattern of template 3 cannot be removed. For isolated three-element patterns such as

1 1

1

the bottom and left elements do not satisfy the edge templates and so must be preserved. Putting the pro- tection conditions together gives a pixel survival condition:

c' ( - e d g e ( c )

+ (edge(E) .N.S)

+ (edge(S) .W.E)

+ ( ( - S E ) .S.E. (edge(S) +edge(E) ) )

+ ( ( - S W ) .W.S. (edge(W) +edge(S) ) )

+ (edge (E).edge (S).edge(SE) ) ) .

Thus, another 22 logical operations are required to compute the survival condition after the edge condi- tions have been calculated.

The Euler characteristic of the three-element pattern

0 0 0 0 c 0 (7)

0 1 1

is preserved after removal of c. The removal of such points in 4-connected thinning methods (Holt et al., 1987) may lead to the complete erosion of staircase branches such as:

1 0 0 0 1 1 0 0

0 1 1 0

0 0 0 0

However, the 8-connected edge definition is such that after a single iteration the lower diagonal pattern of the staircase is removed; therefore, it is additionally safe to remove the end element as well as a unitary thickness diagonal results (no further points can be removed from such a diagonal).

The omission of the template (7) fi'om the edge definition in Section 3 may result in the production of spurious skeletal branches; a pixel c satisfying the three-element pattern (7) on the edge of a dense pat- tern, such as,

0 0 0 1

0 c 1 1

0 0 1 1

is not defined as an edge element and, consequently, it becomes the source of a skeletal line. For example, a thinned image with spurious branches which origi- nate in this way is pictured in Fig. 3 where • denotes a skeletal element and . denotes a pixel which was originally present but is not part of the skeleton. The spurious branch may be removed by extending the definition of edge to include template ( 7 ):

1 1 x x 0 0

1 c 0 1 c 0

1 1 x x 1 x

new template 1 new template 2

z 0 0

1 c 0

z 0 0

new template 3

Page 6: A one-pass thinning algorithm with interference guards

830 A. Stewart/Pattern Recognition Letters 15 (1994) 825-832

~r ~r

. . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . .

Fig. 3.

where a set of z symbols denotes that at least one of these elements is present. A corresponding Boolean condition is:

c' (W' ( - E ) ) ' ( ( N W ' S W ' N ' S )

+ ( ( - ( N + N E ) ) ' ( S + ( ( - S E ) ' ( N W + S W ) ) ) ) ) .

(8)

Again this expression has to be OR-ed to the three rotations of these templates to produce an alternative definition of edge (see Table 2 ). The definition again involves 60 logical operations. The extension neces- sitates a modification to the connectivity argument. An isolated 3-element pattern, such as,

1

1 1

is such that the top and right elements are on edges; in order to avoid the removal of such patterns it is necessary to introduce two new protection conditions:

Table 2 The modified edge function

edge(c). ( - N E ) . e d g e ( N )

• e d g e ( E ) . ( - N W ) . ( - S E ) ,

edge(c). ( - NW).edge (N)

. e d g e ( W ) . ( - N E ) . ( - S W ) .

These conditions only define isolated 3-element pat- terns; consequently, the connectivity argument is un- affected by the addition of these terms. The condi- tions may be simplified to:

e d g e ( c ) . - (NE+ NW).edge(N)

.( ( e d g e ( E ) . ( - S E ) ) + (edge(W). ( - S W ) ) ) .

Conditions (5) and (6) additionally guard against the removal of other 3-element patterns. The modi- fied definition of edge avoids the generation of some spurious branches. For example, the skeleton of the "A" pattern generated by the modified algorithm is displayed in Fig. 4.

Unfortunately, there are occasions in which it may be disadvantageous to remove pixels which satisfy this three-element template (7): the pattern

¢t:¢

is thinned by the original definition of edge to the skeleton

whereas the modified edge definition has the effect of eroding the lower branch to leave the skeleton

The essential problem is that it is not possible to de- termine from a 3 × 3 template whether or not a cen-

edge(NW, N, NE, W, c, E, SW, S, SE) = c . ( ( W . ( - E ) ) . ( ( N W . S W . N . S ) + ( ( - (N+NE) ) . (S+ ( ( - S E ) . ( N W + S W ) ) ) ) ) +

( N , ( - S ) ) . ( ( N W . W . N E , E ) + ( ( - (E+SE)) - (W+ ( ( - S W ) . ( N W + N E ) ) ) ) ) + (E . ( -W)) . ( (NE.SE.N.S) + (( - (S+SW)) . (N+ ( ( - N W ) . ( N E + S E ) ) ) ) ) + ( S ( - N ) ) ' ( ( W S W ' E S E ) + ( ( - (W+NW)) . (E+ ( ( - N E ) . ( S W + S E ) ) ) ) ) )

Page 7: A one-pass thinning algorithm with interference guards

A. Stewart/Pattern Recognition Letters 15 (1994) 825-832 831

• . . * . . . . * . . . .

• . . * . . . . . . . * . . . .

• . * . . . . . . * * . .

• . • * . . . . . . . . . . . . . . . * . . . . .

• . • * . . . . . . . . " e . . . . .

• . • * . . . . . . . * . . . . .

• . . * . . . . . . . . * . . . . .

. . . . . . . . . . . . . . . . . . . . . . - k . .

Fig. 4.

tral pixel should be considered to be (i) the source of a skeletal line or (ii) a piece of noise on the side of a pattern. If the definition of edge is too broad then ex- cessive erosion may take place; alternatively, if the definition is too narrow then spurious branches may be generated.

Spurious branches may also result from the non- detection of other edge elements• For example, the pixel c below

0 0 0 0 1

0 1 c 1 1 0 0 1 1 1 (10)

0 0 1 1 1

is a non-edge element; after one thinning iteration the following pattern emerges:

0 0 0 0

0 0 c 0 1

0 0 0 1 1

Thus, c may act as the source of a skeletal branch. The fork in the lower part of the right limb of the skeleton of the "A" pattern above is derived in this way. This "defect" can also be corrected by the ad- dition of a more general edge template:

x 1 0

1 c 0

x 1 x

In fact, this is the only other non-skeletal template which preserves the Euler characteristic through the removal of the central element. The previous parallel interference arguments are not valid for this more general definition of edge. The use of this template may lead to excessive erosion. For this reason this variation of edge is not considered further.

5. Discuss ion

There are a number of ways of ensuring that the parallel removal of edge elements does not give rise to unwanted effects such as complete removal or al- teration of connectivity. It is possible to introduce a number of sub-iterations, each with a directional bias (Zhang and Suen, 1984). However, such algorithms are relatively expensive to implement compared to one-pass methods (Holt and Stewart, 1989; Holt et al., 1987). Alternatively, parallel interaction can be managed either temporally or specially• For example, Olszewski's algorithm classifies pixels according to their co-ordinate position: thereby a grid can be or- ganised into 4 disjoint subsets - A, B, C and D

a b a b a b

c d c d c d

a b a b a b

c d c d c d

Thus, the 3 X 3 window for any "a'" pixel in the set A does not include any other "a" pixel. Hence, interfer- ence can be avoided by computing the survival con- ditions for each of the sets A, B, C and D in turn• In effect interference is avoided by applying temporal restrictions on the computations. However, it should be noted that this sub-classification of pixels may re- sult in the removal of elements that would be pre- served by one-pass algorithms: pixels that are not on an edge at the outset of an iteration may subse- quently become edge elements after the removal of other elements from the sets A etc. This effect com- bined with Olszewski's definition of edge results in an algorithm which is excessively erosive for certain patterns. For example, the following patterns (or any pattern which may be reduced to them )

Page 8: A one-pass thinning algorithm with interference guards

832 A. Stewart/Pattern Recognition Letters 15 (1994) 825-832

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 1

are all th inned to a single point. For more pro- nounced l imbs the algori thm provides good outlines with excellent noise immunity . The problems of ex- cessive erosion may be avoided by one-pass algo- r i thms which ensure that unwanted interference is avoided by addi t ional safe-guards. The algori thm presented in this paper avoids the problem of stair- case erosion that is encountered in Hol t ' s algori thm by using an edge def ini t ion (Hol t et al., 1987) that detects parallel diagonal lines. Interference safe- guards have been def ined which preserve cont inui ty and avoid the complete removal of patterns.

R e f e r e n c e s

Hilditch, C.J. (1969). Linear skeletons from square cupboards. In: B. Meltzer and D. Michie, Eds., Machine Intelligence I1/~ Elsevier, Amsterdam, 403-420.

Holt, C.M. and A. Stewart ( 1989 ). A parallel thinning algorithm with finer grain subtasking. Parallel Computing 10, 329-334.

Holt, C.M., A. Stewart, M. Clint and R.H. Perron (1987). An improved thinning algorithm. CACM 30 ( 2 ), 156-160.

Olszewski, J. (1992). A flexible thinning algorithm allowing parallel, sequential and distributed application. ACM TMS 10 (1), 35-45.

Wu, R.-Y. and W.-H. Tsai (1992). A new one-pass parallel thinning algorithm for binary images. Pattern Recognition Lett. 13, 715-723.

Zhang, T.Y. and C.Y. Suen (1984). A fast parallel algorithm for thinning digitised patterns. C~tCM 27 ( 3 ), 236-239.