Ultra-fast parallel contour tracking, with applications to thinning

Report 5 Downloads 23 Views
Laboratoire de l’Informatique du Parallélisme

LIP

Ecole Normale Supérieure de Lyon Institut IMAG Unité de recherche associée au CNRS n°1398

Ultra-fast parallel contour tracking, with applications to thinning

Afonso Ferreira Stephane Ubeda

May 1993

Research Report No 93-09

Ecole Normale Supérieure de Lyon 46, Allée d’Italie, 69364 Lyon Cedex 07, France, Téléphone : + 33 72 72 80 00; Télécopieur : + 33 72 72 80 80; Adresses électroniques : [email protected]; [email protected]−lyon.fr (uucp).

Ultra-fast parallel contour tracking, with applications to thinning

Afonso Ferreira Stephane Ubeda May 1993

Abstract This paper proposes a parallel algorithm for contour tracking of binary pictures. Given an object contour composed by O(N) pixels, our algorithm computes in constant time the next layer of the contour of that object, using the weakest parallel model, i.e., an Exclusive Read Exclusive Write (EREW) Parallel Random Acces Machine (PRAM). As an application of the technique we show a work-optimal parallel thinning algorithm for binary pictures, based on Pavlidis' characterisation of a skeleton. Our algorithm improves on previous solutions by producing a list of coordinates corresponding to the skeleton contour in O(N) time with O(N) processors in an EREW PRAM, where N is the width of the picture.

Keywords: Pattern recognition, Skeleton, Parallel complexity, PRAM Resume Nous proposons un algorithme parallele original de trace de contour dans une image binaire. La dimension de l'image etant N  N, l'ensemble des pixels des contours est de taille O(N), notre algorithme calcule alors l'ensemble des pixels des contours apres erosion de ceux-ci en temps constant en utilisant le modele le plus faible de parallelisme, c'est a dire une PRAM a ecriture et lecture exclusives (EREW PRAM). Nous presentons un algorithme parallele d'amincissement d'images utilisant la methode de trace precedemment decrite. Cet algorithme est base sur la caracterisation des squelettes selon Pavlidis. Il est optimal en travail et ameliore les solutions existantes en decrivant le squelette sous la forme d'un tableau de paires de coordonnees de pixels. Cette liste est obtenue en O(N) etapes a l'aide de O(N) processeurs dans le modele EREW PRAM.

Mots-cles: Reconnaissance des formes, Squelette, Complexite parallele, PRAM

Ultra-fast parallel contour tracking, with applications to thinning 

Afonso Ferreira

CNRS - Laboratoire de l'Informatique du Parallelisme E cole Normale Superieure de Lyon 69364 Lyon Cedex 07 - France e-mail: [email protected]

Stephane Ubeda

Laboratoire d'Informatique Theorique Ecole Polytechnique Federale de Lausanne CM-1015 Lausanne, Switzerland e-mail: [email protected] .ch

1 Introduction Most kernels for image processing operate on the object contour. Among them, several algorithms modify the contour in order to obtain some informations. Given an N  N binary image and a description of the contour of an object, the contour tracking problem consists of nding the contour description of the picture that remains after the given contour has been modi ed. The motivation for the use of parallel processing in image related problems stem from a strong urge to improve the performance of existing solutions, in order to bring larger instances under the reach of computer power. We present a parallel contour tracking algorithm for the EREW PRAM model of computation. This algorithm is made of locals analysis of neighbors allowing the modi cation of the contour and the localization of the new contour in constant time. We consider erosion as a particular modi cation of contour and we present how an optimal parallel thinning algorithm can be design with this scheme. At each iteration a contour tracking/extraction is used to check the entire contour and a skeleton based on Pavlidis' caracterization is computed [1]. Similar analyses can be done using erosion or di erent contour modi cation operations to design other parallel image processing kernels such as medial axis computation or digital convex hull computation.

1.1 PRAM models

From a theoretical point of view, many abstract models for parallel machines exist in the literature, and the PRAM (Parallel Random Access Machine) is by far the most preferred model for describing parallel algorithms. This preference stems from the fact that this model lies a mid way between physical reality ? where VLSI models stand ?, and its complete abstraction ? the parallel comparison model ?, while being able to capture the intrinsic parallelism hidden in most problems [2]. A PRAM is viewed as a collection of processors synchronously working on a single instruction

ow that comes from a control unit. Processors have random access to a shared memory, through which interprocessor communication is implemented. Both the size of the central memory (m) and the number of processors (p) are usually de ned as functions of the input size of the problem, say n. The time complexity of a parallel algorithm is measured in terms of the number of parallel instructions performed to complete, say O(f(n)), where f(n) is a function on n. PRAM algorithms are said to be ecient if f(n) = logk n, for some constant k. An algorithm is considered workecient (respectively, work-optimal) if p  f(n) = O(t), where t is the time complexity of the best known sequential algorithm (respectively, the sequential lower bound) for the problem. Since processors are allowed to randomly access the shared memory, con icts can occur while reading from or writing into memory positions. Di erent protocols exist for ruling memory access,  This work has been supported by the CNRS Research Projects C 3 and by the \NANA" EEC ESPRIT Basic Research Action 3280.

1

and each one is the basis of a speci c PRAM model. Therefore, from the weakest to the strongest, one nds the following.

 Exclusive Read Exclusive Write (EREW): concurrent accesses to the same memory position are disallowed in both read and write modes.  Concurrent Read Exclusive Write (CREW): processors can read simultaneously from the same memory location, but concurrent access to the same memory position is disallowed in write mode.  Concurrent Read Concurrent Write (CRCW): concurrent accesses to the same memory position are allowed in both read and write modes. The capability of simultaneously writing in the same memory location creates, again, con icts. Di erent resolving rules lead to di erent CRCW sub-models, and we could list more than a dozen of them [2].

Throughout this paper we shall use the weakest PRAM model, i.e., an EREW PRAM.

1.2 Previous work

As mentioned before, image contours are widely used in various aspects of computer vision, and an increasing interest has been shown for parallel algorithms for contour processing. Dinstein and Landau [3] proposed a parallel contour extraction and coding algorithm that runs on the EREW PRAM architecture in constant time with O(N 2) processors. The stronger CREW PRAM was used by Wu et al. [4] for determining several properties of contours, like union and intersection, in time O(logN) with O(N) processors. As far as parallel contour based algorithms are concerned, Dinstein et al. [5] studied the contourbased 2D shape recognition on EREW PRAM. They described some parallel algorithms for solving di erent features of shape recognition, based on contour extraction and string matching techniques. More recently, Jenq and Sahni [6] tackled the medial axis transform problem and showed a O(logN) time CREW PRAM algorithm with O(N 2 ) processors to solve this problem.

1.3 New results

This papers presents a constant time parallel contour tracking algorithm that requires O(N) processors, where the size of the original contour description is also O(N) pixels. This algorithm is heavily based on some contour properties that we demonstrate in Section 2. The algorithm and its complexity analysis are given in Section 3. In the literature one can nd numerous contourtracking based algorithms. We apply our techniques to Pavlidis' thinning algorithm and derive a skeleton-based optimal parallel thinning scheme for N  N binary images, that runs in O(N) time with O(N) processors. This algorithm is presented in Section 4. We close the paper with some concluding remarks and orientations for further research. All over the paper, we assume N  N binary images with arbitrary objects, but for the fact that we exclude eye-contours (eye-contours are exactly 4 pixels size interior contours). This assumption is made for the sake of clarity of the exposition. Our results apply as well to objects with eyes, but the proofs in Section 2 would become extremely tedious enumerations of special cases.

2 On contour tracking Several algorithms in image processing start by a contour extraction procedure. Once the rst contour is obtained, it is iteratively modi ed until a solution is reached. During this iterative phase, it is important not to be obliged to extract a new contour at each step. In order to avoid this, the contour tracking technique is used, and the new contour can be accessed directly [7]. In the sequential setting, tracking a contour during a shrink operation means that the original contour is deleted from the image, and that a description of the new contour is provided. Unfortunately, under the parallel computing model a new problem arises. Whereas the original contour is given by an allocation of processors to its pixels, one has to specify a \description" of the new 2

contour. But, if coherence is to be kept to start a new contour tracking procedure, then the \description" of the new contour should also be associated with a new allocation of processors to the pixels of the new contour. Therefore, the main question to be answered, before starting to tackle parallel implementations for contour tracking, is how the new contour behaves with regard to the original one. For instance, we must ensure that enough processors are available for the new allocation. Furthermore, the new contour must exhibit some intrinsic characteristics which could be useful for parallel algorithms.

2.1 Locals con gurations

In this Section, we shall prove two main features of a contour obtained by the shrink of an object, namely that,  an increase in the size of the new contour, if any, depends only on some con gurations of the object and not on the size of the image or of the original contour;  there are few such con gurations and they are easily recognizable. Suppose we are given a binary image. The 4-neighborhood of a pixel is composed by its four at most adjacent pixels (immediately above, below, to the right, and to the left), if they exist, and the 8-neighborhood is formed by the 4-neighbors plus at most its four diagonal adjacent pixels, if they exist. Hereinafter, neighbors are to be considered under the 4-neighborhood, unless otherwise explicitly mentioned. The set of 1-valued pixels corresponds to the objects, and the set of 0-valued pixels corresponds to the background or to holes in the objects. Thus, an object pixel belongs to the contour of the object if and only if it is adjacent to at least one background pixel. Direction of the rotation

i

i = pred(j)

Background j

k = succ(k)

k

Object

Figure 1: Computed successor and predessor of a contour pixel. Let N be the width of the image. It is usually supposed that the length of the contour of an object increases proportionally with the resolution of the digitization, i.e., O(N) [1]. We shall represent a processor allocation to an object contour as an array A of size O(N), such that each contour pixel appears only once in A. If A is larger than the contour, then A is completed by nil values. Therefore, a processor pi is in charge of the contour pixel stored in A[i]. A processor pi is said to be active if A[i] holds a pixel coordinate pair. It is inactive ortherwise. Let us call C 0 and C 1 the contour of an object before and after one single shrink operation, respectively. Assume that they are described in clockwise order.

De nition 1 Let i be a pixel in C . Then,  succ(i) is the pixel following i in C , in the 8-neighborhood;  pred(i) is the pixel preceding i in C , in the 8-neighborhood.  Ni is the set of those pixels in the neighborhood of i that belong to C . 0

0

0

1

3

The processor in charge of pixel j inspects its neighbors and computs the predecessor i of j (i = pred(j)) and the sucessor k of j (k = succ(j)) (Fig. 1). Note that i, j and k are names of pixels and not numbers xing any order between the pixels. Recall that we want to bound the size of C 1 . In order to nd a good description of C 1 in terms of C 0 , we shall denote by Ei  Ni the set composed by those pixels that belong to C 1 , only as a consequence of the removal of pixel i, as follows.

De nition 2 A pixel x 2 Ei if and only if either of the following conditions hold (a) Ni = fxg and Nsucc i 6= fxg. (b) Ni = 6 fxg and Npred i 6= fxg and x 62 Nsucc i . Our next goal is to show that this de nition of Ei provides a decomposition of the shrinked contour C . Theorem 1 [ C = Ei ( )

( )

( )

1

1

i2C0

Proof.S

Since Ei  C 1 by de nition, we need only to show that every pixel of C 1 belongs to at least one Ei, for some pixel i in C 0.Let x be a pixel of C 1 . Therefore, x is adjacent to at least one pixel of C 0 . Let i be such a pixel. Then, only one of (a) or (b) holds.

(a) x is the only neighbor of i in C . Then, only one of (a.1) or (a.2) holds. (a.1) x is not the only neighbor of succ(i) in C . Thus, x 2 Ei by de nition. (a.2) x is the only neighbor of succ(i) in C . Then, only one of (a.2.1) or (a.2.2) holds. (a.2.1) Nsucc succ i is not fxg. Thus, x 2 Esucc i by de nition. (a.2.2) Nsucc succ i is fxg. Then, only one of (a.2.2.1) or (a.2.2.2) holds. (a.2.2.1) Nsucc succ succ i is not fxg. Then, x 2 Esucc succ i by de nition. (a.2.2.2) Ni, Nsucc i , Nsucc succ i and Nsucc succ succ i equal fxg. This is impossible 1

1

1

(

( ))

(

( ))

(

( )

(

( )))

( )

(

(

( ))

(

(

( ))

( )))

because eye-contour is not considered. (b) x is not the only neighbor of i in C 1, then only one of the following holds. (b.1) x is not a neighbor of succ(i) and not the only neighbor of pred(i). Thus, x 2 Ei by de nition. (b.2) x is not a neighbor of succ(i) and it is the only neighbor of pred(i). Then, x 2 Epred(i) by de nition. (b.3) x is the only neighbor of succ(i). Thus, x 2 Esucc(i) by part (a). (b.4) x is not the only neighbor of succ(i). Then the part (b) is recursively applied, with i replaced by succ(i). Successive applications of part (b) must end because eye-contour is not considered.



We are trying to nd a bound on the size of the new contour C 1 . If the sets Ei formed a partition of C 1 , then our task would be easier. Unfortunately, this is not the case since the shrink may cause the collapsing of two opposite parts of the contour C 0 in such a way that a pixel in C 0 belongs to Ei and Ej , i; j 2 C 0 , and i 6= j. Therefore, we shall instead consider bounds on the size of the sets Ei.

Theorem 2 8i; i 2 C ; 0  jEij  2. Proof. Let us consider a pixel i in C . (a) i may have no neighbors in C . Its only neighbors are in the background or in C . 0

0

1

0

4

(b) i may have at most 3 neighbor pixels in C , since one is in the background. Suppose this number is exactly 3. One of these neighbors is also a neighbor of succ(i). Then, by De nition 2 such a neighbor cannot be in Ei .  Let now k be the number of pixels in C for which their removal may increase the size of the 1

0

0

contour description. Formally, De nition 3 k0 = jfi s:t: jEi j = 2gj. Therefore, Corollary 1 jC 1j  jC 0 j + k0.

Interior

Background

Direction of rotation

Previous and next pixels of the considered pixel

Considered pixel

P2

P1

P3

P5 P4

P6

P7

P10

P8

P9

P11

P13 P12

Figure 2: All possible patterns of the sequence pred(i), i, succ(i). Clearly, the increasing in the size of the new contour C 1 depends heavily on the parts of the object where the set Ei has two elements. In the next Section we shall study such con gurations (called augmenting con gurations and show that k0 depends only on the objects shape). 5

2.2 Augmenting con gurations Number P1 P2 P3 P4 P5 P6 P7 E 0 0 0 0 or 1 1 1 0 Number P8 P9 P10 P11 P12 P13 E 0 0 or 1 1 0 or 1 1 or 2 0, 1 or 2 Table 1: Values of Ei for each pattern of pred(i), i, succ(i). Figure 2 shows all possible con gurations of pixels pred(i), i, succ(i), up to a 90o rotation. There are 13 di erent patterns. Let i be the pixel at the center of each depicted con guration. Table 1 shows the possible values of Ei, varying with the considered con guration. Notice that the only con gurations where Ei may have two elements are P12 and P13. In order to know the exact con gurations that yield two elements in Ei, we shall consider the pixel pred(pred(i)). Notice, in Figure 3, that these con gurations correspond to speci c obtuse angles in the image. Thus, k0 must be very small compared to the size of the contour. Moreover, k0 depends only on the image shape: an increase in the image resolution, leading to an increase in the size of its contour, does not change the value of k0 . Hence, we can say that C 1 may be only a constant number of pixels larger than C 0.

O1

O2

O3

Background

O

5

Next contour

O

4

Figure 3: O con gurations with an Ei of cardinal 2. Therefore,

Proposition 1 Let a binary image be given. After a single shrink operation, an increase in the size of the new contour, if any, is independent of the size of the original contour.

3 Parallel contour tracking Since a parallel contour extraction algorithm exists [3], we concentrated our e orts on the design of an EREW PRAM algorithm for the tracking phase. The contour modi cation considered below is the shrink of the object, where successive contour peelings are applied. The growing of the object can be solved in essentially the same way. Our algorithm shrinks the object and produces one allocation for the new contour. We rst show how a single peeling operation can be implemented in constant parallel time. To achieve this time complexity we have to prove that the new contour can be found with local informations only. Then, we study parallel contour tracking for successive contour peelings. 6

In the following we shall show how to compute a new allocation for C 1 , as well as some properties of such allocation. Further, we shall show that the new allocation may require a few more processors than the previous one, depending only on the shape of the object but not on its width. Finally, it is shown that I peeling steps of contour tracking can be performed in parallel by O(N) processors in O(I) time.

3.1 Decomposition of the neighborhood

Let us be given an object from a binary image, its contour C 0, and an allocation A0 for C 0 . Note that pi can check in constant time the neighborhood of pixel i. Therefore, we do not need the explicit description of the contour in order to nd succ(i) and pred(i). The parallel contour tracking operation begins with only the active processors (the ones allocated to C 0 ), and can be described as follows. Algorithm ParallelContourTracking 0 Input: an object contour C . 1 0 Output:a contour C representing the contour of the object less its original contour C . 1. the pixels of C 0 are removed. 2. the new contour C 1 is built. 3. a new allocation A1 for C 1 is computed.

Analysis. Step 1 trivially takes constant time, since it suces that each pi erases pixel i from the image (coordinates are in A0 ). By Theorem 1, Step 2 is implemented by letting each pi nd the sets Ni and Ei , which, by De nitions 1 and 2 can be done in constant time. Implementing Step 3 is less straightforward because con icts among processors may appear during the allocation process. A processor pi will be in charge of the allocation of some of the pixels of C 1 , de ned by the set Ei, and, depending on the cardinality of this set, processor pi will become inactive (jEij = 0) or will allocate the pixel in Ei (jEi j > 1). We say that a local con ict occurs when two processors want to allocate the same pixel in C 1 while they were allocated to consecutive pixels in C 0 . Any other con ict is said to be non-local, and they may appear due to foldings in, or to the collapsing of two opposite sides of, the original contour caused by the shrink operation. Fortunately, the de nition of the sets Ei allows us to concentrate in non-local con icts only, because local con icts are impossible to happen, as shown below.

Theorem 3 8i; i 2 C ; fEpred i \ Ei = ;g Proof. Let x be a pixel of Epred i . Then, either the statement of De nition 2-a or the statement of De nition 2-b is true, both are contradictory with x 2 Epred i .  Now, by means of a very simple priority strategy we can get rid of non-local con icts. All processors rst allocate a pixel from their E sets if it is a north-neighbor, and mark it as done. Then, they do the same with east-neighbors, again with south-neighbors, and nally with west-neighbors. After this step, each pixel of C has been allocated to exactly one processor, since a pixel cannot be the north (respectively east, south, west) elected neighbor for two di erent processors. Moreover, all C have been allocated because all four directions of the neighborhood were considered. Thus, the only remaining problem is for those processors with jEi j = 2, since they received two pixels during the allocation step, and A should allocate exactly one pixel coordinate pair per processor. 0

( )

( )

( )

1

1

1

This may happen, as seen in the previous Section, only for the con gurations P12 and P13 of the Figure 2. Such con gurations represent certain obtuse angles in the contour, for which the number of pixels in the next contour, after the shrink, is larger than the number of corresponding pixels in the original contour. In order to avoid the access to global information when keeping an allocation of the processors to the new contour, some new processors have to be added locally. Therefore, a processor pi in charge of nding an allocation for two pixels in the new contour must rst allocate one of them to itself ? by inserting the coordinates of the chosen pixel in the position i of the new 7

allocation A1 {, and then activate an idle processor pj ? by inserting the coordinates of its second pixel in the position j of the new allocation A1 . During the phase where the object contour is obtained (by a contour extraction algorithm), it is possible to detect the con gurations (and hence the processors) where (for which) allocation problems may arise and then reserve idle processors in the array A1 for such active processors. Therefore, Step 3 also takes constant time.

Theorem 4 Let an N  N binary image be given, along with a O(N) contour description of an object in the image. Then, its contour tracking can be done in constant time by O(N) processors on an EREWPRAM . Proof. The time complexity stems from the discussion above. The total number of processors required to track the new contour is the number of originally active processors plus the number of obtuse angles aforementioned. If we recall that Proposition 1 states that the latter is a constant, independent of the size of the original contour, then the theorem follows.  This result is intrinsically interesting, but most applications require more than one single shrink operation. In the following, we extend the theorem above to parallel contour tracking of repeated image shrinking.

3.2 Iterative contour tracking

Now we prove that the previous results imply that successive contour peelings composed by I shrink operations can be executed in time proportional to I, if we are able to detect the augmenting con gurations (denoted O) in the contour C t+1 in constant time, knowing the O con gurations of C t . Figure 4 depicts all possible Oq ; 1 < q < 5, up to rotations in the object. For this purpose, we need an extension of the value k0, from De nition 3.

De nition 4 Let kt be the number of con gurations in C t which may induce an increase in the size of the description of contour C t , with regard to the description of C t . I.e., kt is the number of O con gurations in C t . +1

The constant kt, that also represents the number of auxiliary processors required for tracking thePnew contour after a shrink operation, varies at each step t. We are then interested in the value of It=0 kt. In order to bound this value, we shall rst study the possible locations of the augmenting con gurations of the shrinked contour, with regard to the position of their counterparts in the original contour. We then prove that every augmenting con guration of the shrinked contour should have been created by an augmenting con guration of the original contour, and that each augmenting con guration of the original contour creates at most one new augmenting con guration in the shrinked contour.

Proposition 2 During an object shrink by contour peeling, in a contour C t , t 6= 0, there exist no

O2, O3, or O5 augmenting con guration.

Proof. The proposition results from a case study. We show here that an O3 augmenting con guration cannot appear in such contours. The other cases are similar and we leave their proofs as an exercise to the interested reader. Suppose that there is an O3 in C t , t 6= 0, described by the pixels A, B, C, D, in Figure 5, and de ned by the function succ. The background pixels P, Q, R, are neighbors of A, B, C, D. Therefore, P, Q, R, belonged to C t?1 before the peeling. However, it is clear that R could not belong to C t?1, because R had then no background neighbors, leading to a contradiction.  Lemma 1 All augmenting con gurations in C t , t 6= 0 are adjacent to an augmenting con guration in C t? . Proof. By Proposition 2, we have only to prove the lemma for O and O . Let us consider an O augmenting con guration in a contour C t , t = 6 0. This con guration is represented by the pixels 1

1

1

8

4

O −> O 1

O2 −> O

1

O3 −> O

1

1

Background

O4 −> O4

O5 −> O4 Next contour

Figure 4: Adjacent augmenting con gurations in contiguous contours. P

A

R

Q

D

C

C 1 B Interior

Background

Figure 5: Illustration of a forbidden augmenting con guration. A, B, C, D, in Figure 6, de ned by the function succ. Pixels Q, R, l, are background neighbors of A, B, C, D, and therefore, were part of C t?1 . Pixel P is also in the background, otherwise C could not be the successor of B. Furthermore, pixel P was not part of C t?1 , otherwise l would not be in C t?1. Note that, in C t?1 , R = succ(S) and S = succ(Q), and the predecessor of pixel Q was one of X, Y , or Z. Thus, there are only three possibilities. pred(Q) = X : then X, Q, l, R formed an O3 augmenting con guration. pred(Q) = Y : then Y , Q, l, R formed an O2 augmenting con guration. pred(Q) = Z : then Z, Q, l, R formed an O1 augmenting con guration. Hence, an O1 augmenting con guration in a contour C t , t 6= 0, is adjacent to an augmenting con guration in C t?1. The proof for O4 is analogous.  Therefore, processor pi , which is in charge of the augmenting con guration Oq in C t , can explore its neighborhood in order to nd if there is an augmenting con guration in C t+1 , created by the removal of Oq .

Corollary 2 The O con gurations of C t can be localized in constant time during the tracking +1

operation.

9

X

Y

Z

P

Q

A

S

R

B

D

C

C1 Background Interior

Possible previous of Q

Figure 6: Illustration of O1 adjacency. It remains, thus, to be determined the global behavior of the constants kt , for 0  t < I. Again, this is a matter of a tedious case study that yields the following. Theorem 5 8t > i =) kt < ki. Proof. To prove the theorem, it suces to show that an O con guration in C t is adjacent to at most one augmenting con guration in C t+1 . Suppose that there is an O1 in C t, described by the pixels A, B, C, D, in gure 7, and de ned by the function succ. We consider that the origine of an O con guration is the third pixel of the sequence (namely C in gure 7). If one of the P, Q, R, S pixels not in C t+1 , then j or k can not be origine of an O con guration in C t+1 . If P, Q, R, S are in C t+1 then k is the origine of an O1 con guration in C t+1 and Q can not be origine of another O con guration in C t+1. Hense an O1 augmenting con guration of C t is at most adjacent to an O1 con guration in C t+1. The proofs for O2, O3 , O4, O5 are analogus.  C

A B

0

P Backgournd

D

C

S

R

Q Interior

Figure 7: Illustration of O1 evolution. And nally,

Corollary 3

XI k  Ik : t=0

t

0

Now we are able to state our main theorem concerning iterative contour tracking. The number of processors needed for tracking a given contour during I shrink operations is clearly bounded above by the size of the original contour plus a quantity, independent of the image size, N, given in corollary 3. Hence, Theorem 6 Let an N  N binary image be given, along with a O(N) contour description of an object in the image. Then, tracking the contour during I iterations of shrink operations can be implemented in O(I) time with O(N) processors on an EREWPRAM . 10

Applications of this theorem stem from algorithms that use iterative shrinking as a building block. As an example, a parallel contour based thinning algorithm is shown in the next Section.

4 Application to thinning The thinning transformation is a derivative of the medial axis transformation. Blum [8] has described the medial axis transformation in the continuous plane as a shape descriptor allowing both data reduction and description. It can be de ned with the help of the grass re concept, where the object is seen as a meadow. A re is lit along its contour such as all re fronts invade the object with the same speed. The medial axis of the object is the set of points reached by more than one re front at the same time (see Figure 8).

Object

Medial axis

Figure 8: Medial axis of a continuous object. The thinning tranformation is the discrete implementation of the re grass concept and its result is a skeleton, for which giving a simple and rigorous de nition is a challenging problem [9, 10, 11].

4.1 Characterisation of a skeleton

A thinning algorithm takes as input an N  N image which contains one object, and produces an N  N image with the skeleton of the original object. It is known that the skeleton produced by a thinning algorithm should satisfy a number of conditions [1]. Be homotopic. It is a basic requirement that any thinning algorithm must preserve connectivity of both the object and the background. Be signi cant of elongations. Skeletons are shape descriptors. Therefore, skeleton branches must be meaningful of the elongation of the original object. This condition is well used, although no formal de nition for elongation could be found. It is usually expressed through the end points of the object, where an end point is a pixel having a single neighbor in the object. Have some noise immunity. Since elongations are not formally de ned, the condition above can hardly avoid distorsions on the skeleton. Undesirable branches can appear due to some noises in the contour which appear during an iteration of the thinning algorithm, confused with the real end points. Thinning algorithms should be immune to these noises as much as possible. Again, many applications and authors are concerned with problems of noise. Pavlidis in [12] notes that noise sensitivity is a general property of thinning schemes, even in the continuous plane. However, we cannot nd a universal de nition of noises. Be 1-pixel thick. A skeleton is a set of curves. In order to be able to use these curves to their best, they must be as thin as possible. Be isotropic. A shape descriptor has to be invariant with the position of the object in the image. That means that thinning must be invariant under translation and rotation. Notice that this condition does not hold in the digital plane, since rotations are no longer invariant transformation in the 11

digital plane (except for 4 rotation). Hence, the thinning process must delete pixels symmetrically. This can be expressed by the following skeleton property. Preserve symmetry. Isotropy and symmetry involve that a skeleton should be closely related to the medial axis of the object. Recall that thinning transforms and medial axis transforms are the same in the continuous plane [13]. Most of thinning algorithms are designed to match the aforementioned conditions with the obtained result being called skeleton. Our parallel thinning algorithm is based on Pavlidis' new approach for thinning. He started from a formal de nition of the skeleton and conceived his algorithm so as the result would be such a skeleton. In the following we recall the basic aspects of Pavlidis' algorithm.

4.2 Contour based thinning algorithm

A 1 valued pixel in a binary image belongs to its contour if and only if it has at least one 0 valued neighbor. Pavlidis has proposed a strict de nition of the skeleton of an object, as a connected set of multiple pixels [1]. Even though the multiple property of a contour pixel is local, it can be checked during a contour tracking algorithm [12]. It can be de ned as follows. De nition 5 A pixel p is multiple if one or more of the two following conditions hold. A) p is traversed more than once during a contour tracking. B) p has no neighbors in the interior of the object. C) p has at least one neighbor which belongs to the contour but which is not its predecessor nor its successor during a contour tracing.

b

a c

d

Figure 9: Pixel a is multiple because of Condition A; pixel b is multiple because of condition B; pixel c is multiple because of condition C. Pavlidis' thinning algorithm consists of successive contour tracing steps until the remaining contour pixels are labelled as skeleton pixels. The de nition of a skeleton pixel is: De nition 6 A pixel p belongs to the skeleton of an object if at least one of the following conditions

hold.

p is multiple. b) p is adjacent to a skeleton pixel already identi ed. Condition b, above, is necessary to ensure the connectivity of the skeleton. The de nition of skeleton pixel is used constructively in the algorithm. Successive peelings of the contour are made until all remaining pixels belong to the skeleton. The thinning algorithm is as follows [1]. a)

12

Algorithm Thinning Input: an object contour. Output:the skeleton of the object. 1. all contour pixels are checked during a contour tracking and skeleton pixels are labelled; 2. all contour pixels not labelled skeleton are removed from the picture; 3. if the remaining image is more than only skeleton pixels, then go to 1

To analyse the complexity of this algorithm, note that each contour tracking operation takes time proportional to the size of the image contour, and it is called a number of times proportional to the width of the original image. It is usually supposed that the length of the contour of an object increases proportionally with the resolution of the digitization [1]. Therefore, the contour size and the width of an N-dimensional image are both proportional to N. Hence, sequential thinning takes (N 2 ) time. In [14] an improved version of the original algorithm was proposed which ensures a better quality of the resulting skeleton. However, the structure of the algorithm remains the same, as well as its time complexity.

4.3 Parallel thinning

This section presents a parallel approach to thinning. We show that the diculty of designing a parallel algorithm lies on the allocation of processors. A direct parallel implementation of Pavlidis algorithm is rst described. Before starting the iteration of the Thinning algorithm shown above, an initial processor allocation must be found. Existing parallel contour extraction and labelling can be used [3]. Such an algorithm stores in a one dimensional array the coordinates of the pixels of the contour, what gives us the rst allocation. This can be done in O(logN) time using O( logN 2N ) processors. If this parallel contour extraction is used again in step 3, then a new allocation is found in O(logN). In the worst case, the Thinning algorithm is iterated O(N) times. Thus, the parallel algorithm runs in O(N logN) time with O( logN 2N ) processors. Therefore, this algorithm is not workoptimal. The arguments above show that a straightforward parallelisation does not yield good results at all. fortunately the tools we developed in the previous Sections can now help us to trivially solve this problem, as following. The parallel contour extraction algorithm from [3] can be implemented in O(N) time with O(N) by the simulation principle [2]. Starting from the allocation given by such an algorithm, we can nd the allocations for the successive eroded contours through the parallel contour tracking algorithm described in the previous Section. Each tracking iteration costs then O(1). Therefore,

Theorem 7 Let an N  N binary image be given, along with a O(N) contour description of an object in the image. Then, Pavlidis' thinning algorithm can be implemented in O(N) parallel time, with O(N) processors in an EREWPRAM .

5 Conclusion We showed how a contour tracking procedure can be implemented in O(1) parallel time. To achieve this complexity we had to prove a number of properties of object contours in binary images. Then, we applied our parallel contour tracking algorithm to optimally solve the thinning problem. A work-optimal parallel implementation of Pavlidis' thinning algorithm was introduced for an EREW PRAM. Our technique can be extended to other contour based thinning algorithm. Pavlidis' algorithm has been chosen because of it rigorous de nition of the resulting skeleton. Our solution runs in O(N) parallel steps, due to the contour peeling technique. This bound cannot be improved using Pavlidis' algorithm. In order to obtain a O(logN) time parallel thinning algorithm each iteration must reduce the width of the object by a constant factor, while keeping track of the shape of the object, which Pavlidis' algorithm can not do. 13

References [1] T. Pavlidis. A thinning algorithm for discrete binary images. Computer vision and image processing, 20:142{157, 1980. [2] R. Karp and V. Ramachadran. A survey of parallel algorithms for shared-memory machines. Technical report ucb/csd 88/408, university of california, Computer Science Division, 1988. [3] I. Dinstein and G.M. Landau. Parallel algorithms for contour extraction and coding on an erew pram computer. Pattern Recognition Letters, 11:87{93, 1990. [4] A.Y. Wu, S.K. Bhaskar, and A. Rosenfeld. Parallel processing of region boundaries. Pattern Recognition, 22(2):165{172, 1989. [5] I. Dinstein, G.M. Landau, and G. Guy. Parallel (erew pram) algorithms for contour based 2d shape recognition. Pattern Recognition, 24(10):929{942, 1992. [6] J.F Jenq and S. Sahni. Serial and parallel algorithms for medial axis transform. IEEE Transactions on Pattern Analysis and Machine Intelligence, 14(12):1218{1224, 1992. [7] A. Rosenfeld and A. C. Kak. Digital Picture Processing. Academic Press, New-York, 1989. [8] H. Blum. A Transformation For Extracting New Descriptors. Symp. On Models for perception of speech and visual form, MIT Press, 1964. [9] C. Ronse. A topological characterization of thinning. Theoretical Computer Science, 43:31{41, 1986. [10] Y. Xia. A new thinning algorithm for binary images. In Eighth International Conference on Pattern Recognition (Paris, 1986), pages 995{997, 1986. [11] R.W. Hall. Fast parallel thinning algorithms: Parallel speed and connectivity preservation. Comm. ACM, 32:124{131, 1989. [12] T. Pavlidis. Structural pattern recognition. Springer-Verlag, 1977. [13] A. Montanvert. Medial line: Graph representation and shape description. In Eighth International Conference on Pattern Recognition (Paris, 1986), pages 430{432, 1986. [14] C. Arcelli. Pattern thinning by contour tracing. Comp. Graph. and Image Proc., 17:130{144, 1981.

14

Appendix : illustration of a contour tracking made by erosion

Figure 10: The gradation of grey color illustrate the erosion front propagation in the object. Black pixels correspond to encountered O con guration during the process.

15