RESEARCHCONTRIBUTIONS Image Processing and Computer Vision Robert M. Haralick Editor A Fast Parallel Algorithm for Thinning Digital Patterns T. Y. ZHANG and C. Y. SUEN ABSTRACT: A fast parallel thinning algorithm is proposed in this paper. It consists of two subiterations: one aimed at deleting the south-east boundary points and the north-west corner points while the other one is aimed at deleting the north-west boundary points and the south-east corner points. End points and pixel connectivity are preserved. Each pattern is thinned down to a "skeleton" of unitary thickness. Experimental results show that this method is very effective. 1. INTRODUCTION It is well known that the general problem of pattern recognition lies in the effectiveness and efficiency of extracting the distinctive features from the patterns. The stroke analysis method is a powerful approach to recognizing certain types of digital patterns such as alphanumeric characters and ideographs. It should be noted that the strokes thinned by hardware or software are accompanied by different kinds of distortion. Different thinning algorithms produce different degrees of distortion [1-5, 7-12]. There is no general agreement in the literature on an exact definition of thinness. Pavlidis [6] describes a thinning algorithm that determines skeletal pixels by local operations. At the same time, the pixels are labeled so that the original image can be reconstructed from its skeleton. The goal of this paper is to find a © 1984 ACM 0001-0782/84/0300-0236 75¢ 236 Communications of the ACM faster and more efficient parallel thinning algorithm. The distortion should be as little as possible. Experimental results indicate that this method can be used to thin a variety of digital patterns. 2. PARALLEL PICTURE PROCESSING A binary digitized picture is defined by a matrix IT where each pixel IT(i, j) is either 1 or 0. The pattern consists of those pixels that have value 1. Each stroke in the pattern is more than one element thick. Iterative transformations are applied to matrix IT point by point according to the values of a small set of neighboring points. It is assumed that the neighbors of the point (i, j) are (i - 1, j), (i - 1, j + 1), (i, j + 1), (i + 1, j + 1), (i + 1, j), (i + 1, j - 1), (i, j - 1), and (i - 1, j - 1), as is shown in Figure 1. In parallel picture processing, the new value given to a point at the nth iteration depends on its own value as well as those of its eight neighbors at the (n - 1)th iteration, so that all picture points can P, (i- 1, j- 1) P2 (i- 1, j) P3 (i- 1, j+ 1) P, P1 (i, j) P, P~ Pe Ps (i+ 1 , j - 1) (i+ 1,j) (i+ 1,j+ 1) (i, j - 1) (i,j+ 1) FIGURE 1. Designations of the nine pixels in a 3 x 3 window. March 1984 Volume 27 Number 3 Research Contributions be p r o c e s s e d s i m u l t a n e o u s l y . It is a s s u m e d t h a t a 3 x 3 w i n d o w is used, a n d t h a t e a c h e l e m e n t is c o n n e c t e d w i t h its e i g h t n e i g h b o r i n g e l e m e n t s . T h e a l g o r i t h m presented in this paper requires only simple computations. In t h e s e c o n d s u b i t e r a t i o n , o n l y c o n d i t i o n s (c) a n d (d) are c h a n g e d (Figure 3) as follows: (c') P2*P4*P8 (d') P2*P6*P8 3. T H I N N I N G A L G O R I T H M O u r m e t h o d for e x t r a c t i n g t h e s k e l e t o n of a p i c t u r e consists of r e m o v i n g all t h e c o n t o u r p o i n t s of t h e pict u r e e x c e p t t h o s e p o i n t s t h a t b e l o n g to t h e s k e l e t o n . In o r d e r to p r e s e r v e t h e c o n n e c t i v i t y of t h e s k e l e t o n , w e d i v i d e e a c h i t e r a t i o n into t w o s u b i t e r a t i o n s . In t h e first s u b i t e r a t i o n , t h e c o n t o u r p o i n t P1 is del e t e d from t h e digital p a t t e r n if it satisfies t h e f o l l o w i n g conditions: = = 0 0 a n d t h e rest r e m a i n t h e same. By c o n d i t i o n s (c) a n d (d) of t h e first s u b i t e r a t i o n , it will be s h o w n t h a t t h e first s u b i t e r a t i o n r e m o v e s o n l y t h e s o u t h - e a s t b o u n d a r y p o i n t s a n d t h e n o r t h - w e s t corn e r p o i n t s w h i c h do not b e l o n g to a n ideal s k e l e t o n . T h e p r o o f for t h e first s u b i t e r a t i o n is given, t h a t is, t h e p o i n t s to b e d e l e t e d satisfy c o n d i t i o n s : (a) 2 _< B(P1) -< 6 0 (C) P2*P4*P6 = 0 (d) P4*P6*P8 : P~ 0 1 I 0 0 \2 J is t h e n u m b e r of n o n z e r o n e i g h b o r s of FIGURE 2. Counting the 01 patterns in the ordered set P2, P~, P4, .... P~, P~. P1, North t h a t is, P2 B(P1) = P2 + P3 + P4 + • • • + P8 + P9. West Pa Pl If a n y c o n d i t i o n is not satisfied, e.g., t h e v a l u e s of P2, P3, P4, • • - P9 as s h o w n in Figure 2, t h e n Pa FIGURE 3. Pointsunder consideration and their locations• T h e r e f o r e , P~ is n o t d e l e t e d from t h e p i c t u r e . .@~.~• @.~@. ~ @@@@@@8@. @@8@@88~. @8@@8@@@. @@@@@@~8. @8#@@8@@. @@8@@@@~. @8@@@@8@. @@~0@@@8. .@@8@8@8 .@@@8888 .88@8@8@ #@@@@@@@. @@@@@~@@. .@@8@~@@ @@@~@8@@. @@@@@@@@. .@88@8@@ @@8@~@@8. @@8@@8@@. ~8@@8@@@. 8@~@@@@@. @@~@@88@. @@@@@@@@. .@8@@@88 .88888@~ .8@@@@@@ @~8@8@@@@@@88@@@8@@@@@8@@8@. 8808@@88088@8@@@@@@@@~8~8@8. @@@@@@@O@@@@@@@@O@@@@@@~@@@. @@8@888@8@88@8~@8@@8~@@@@8@. 888@8@8~8@@@@@8@@8@@@@@#@0. @@@~@@@8~8@8@8@@8@@@@@@~8@8. @888@@88~ . . . . . . . . . . 888~88@@. @@@@@8@@. @@@@@@@@. @@@@@@8@. @@@@8~@@. @@@@@0@@. @@@@@8@@. ~#@@@@@8. @@@@@~8@. 8@@@@8@@. #@@@@0@@. 888@@8@~. @8@@@@@@. 8~8@@@@@. @@@@@@@@. ~@#@@@#. @@8@@@#8. #@#@@088. @@@@@@@@. . . . . . . . . o . . . . . . (a) East P4 South A(Pi) = 2 °•o I 1 0 = w h e r e A(P1) is t h e n u m b e r of 01 p a t t e r n s i n t h e o r d e r e d set P2, P3, P4, - • - P8, P9 t h a t are t h e eight n e i g h b o r s of P1 (Figure 1), a n d B(Pi) 0 i (b) A(P~)= 1 . • ° . . . . .@@@@88@ .8@@8@@@ .@@@8@8@ .@@@@8@@ .@@~8@@@ .@@@@@@@ .@@@@88@ .@@@8@@8 .@@@@@0@ .@@@@@@@O@@@@@@@@@@@@@@@@@@ .@@@@@@@@@@@@#@@O@~@@@@@@@@ .~88@@8@@@@@~@~8@8@@@@@@@@@ .8@8@@@@#@88@@@@@@8@@@@@8@@ .@@@@@@@@@8@@@@088@@@@@@@@@ .@@@8@8@ .@@8@@@8 • 8@@@8@@ .@@@8@@@ • @@@8~@@ .@888@@~ 8@@@@@@ .@8@@@@@ @@@@@@0 .@@@@88@ @88@8@8 .@@@8@88 @8@@@@@ .@@@8@@@ @@8@@@@ .@8@@@@@ @@8@@@8 .@@@@@@~ @@@@@@. .@@@8@@. . . . . @° .'. .° .@ . . . . ~o .• • ° o@.,°° . . . . @. .° .. .@ . . . . @. .. .. °@ . . . . °° °@ . . . . • °@o °° .°@.,o. . . . . . . . . . . . . . . . . . . . . . . ~ .... ..@ . . . . . . . . . . . . . . . . . . @ .... ..@ . . . . . . . . . . . . . . . . . . @ .... .8@@@@@@@@@~8@@8@#@@@ .... • .@ . . . . . . . . . . . . . . . . . . @. . . . • .@. . . . . . . . . . . . . . . . . . @. . . . ..~ . . . . . . . . . . . . . . . . . . --@ . . . . . --@ . . . . . .-@ . . . . . ..8 . . . . . • .@ . . . . . .................. . . . . . . . . . . . . . . . @.o• ~... @... ~... ~... 8... .................. .................. (b) (c) FIGURE 4. Resultsof thinning the character 'H' by the subiterations. March 1984 Volume 27 Number 3 Communications of the ACM 237 Research Contributions (c) P2*P4*P6 = 0 (1) (d) P4*P6*P8 = 0 (2) 0 O-- 0 I I I The solutions to the set of equations (1) and (2) are P4 = 0 or P6 = 0 or (P2 = 0 and Ps = 0). So the point P1, which has been removed, might be an east or south boundary point or a north-west corner point. Similarly, it can be proved that the point P1 deleted in the second subiteration might be a north-west boundary point or a south-east corner point. For example, the results of processing the character "H" by both subiterations are shown in Figure 4(a) and 4(b). The points marked by " . " have been removed. The final result is shown in Figure 4(c). By condition (a), the endpoints of a skeleton line are preserved. Also, condition (b) prevents the deletion of those points that lie between the endpoints of a skeleton line, as shown in Figure 5. The iterations continue until no more points can be removed. A flowchart of the proposed thinning algorithm is shown in Figure 6. Initially, the original picture is stored in matrix IT and a counter C is set to 0. The result of the processed picture is stored in matrix IT. To save m e m o r y space, only two matrices, IT and M, are used in our computation. Figures 7(a)-7(c) show the results obtained by our algorithm for a Chinese character "@," a letter "B," and a digital "moving body," respectively. Skeleton points are marked by "*," or "@," and all those points that have been deleted in the thinning process are marked by " - . " The above algorithm yields very good results with respect to both connectivity and contour noise immunity. Furthermore, the conditions for searching those points that should be deleted from the pattern are very simple. In order to assess the performance of our algorithm, we have chosen one given by Stefanelli and Rosenfeld [11] for comparison. Both algorithms were written in FORTRAN, run on the same CDC Cyber 172 computer, and tested with the same digitized patterns. The result shows that the execution time of our algorithm is only 50 percent of the one given [11]. As can be predicted, the execution time depends on the complexity of the pattern and the thickness of the strokes: 0.505 CPU seconds for the Chinese character " ~ " 0.454 CPU seconds for the letter "B" and 1.163 seconds for the moving body. 0 i 1 I 1 1 0 ,0 0 0 0 1 1 I 1 ; 0 O. 0 0 ~ 0 I 1 1 I 0 ~ 0 0 FIGURE 5. Preventin9 the deletion of endpoints. Start I l ) C=O Search M (satisfied the conditions of the first subiteration) C = C+l, ifM(i,j) = 1 IT = IT - M Yes C=O Search M (satisfied the conditions of the second subiteration) C = C + 1, if M(i,j) = 1 IT = IT - M TABLE I. Comparison of CPU Time (in seconds) Consumed by Different Parallel Thinning Algorithms Pattern B •~ Movingbody 238 Method Yes Four-Step Two-Step Our Algorithm 0.765 1.031 2.713 0.678 0.882 2.221 0.454 0.505 1.163 Communications of the ACM FIGURE 6. Flowchart of the thinning algorithm. March 1984 Volume 27 Number 3 Research Contributions . . • ~ ..,.--- ... . . ...... • ..... ,i ....... 1,2 ~i *,,;;'. '~,2 ..... ; ............ .H,,,, • ..,. .... . iii ..... ottt @ ........ @@.. .@ • .@. ° .@ • °@o .@ °@° .@ • °@° .@ • o@• .@ • •@o .@ • .@• • .@ • .@@.. .@ ° • o@o ° .@ . . . . . . . . . @. .@@@@@@@@@@@.. .@ . . . . . . . . . .@. .@. .@. .@ . . . .@. .@. .@. .@. .... .............. ~e . . . . . . . . . . ...... "" i ; . . . . . • • . • ~ ~2j,~ ~ .... ~ • ° @@.. . .@@.. . .@... . .@.. . @.. . .@.. . .@.. . .@... . .@@.. 222,1 ~.2. "~;;22 .* ........ ..~... ..... @.......... @@.. ..@@@@@@@@@@@@@@@@.. oo• . . . . . . (a) ::~;:::: • . • • o ~ o o • (c) (b) FIGURE 7. Thinning of different digital patterns. 4. S U M M A R Y A parallel algorithm for thinning different types of digital patterns is presented in this paper. Each iteration is divided into two subiterations that remove the boundary and corner points of the digital patterns. After several iterations, only a skeleton of the pattern remains. The proposed algorithm appears to be very efficient in the thinning of digital patterns and it compares favorably with those described in [11]. The results in Table I indicate that our method is 1.5 to 2.3 times faster than the four-step and two-step methods described in [11] while the resulting skeletons look very much the same. REFERENCES 1. Arcelli, C., Cordelia, L.P. and Levialdi, S. From local maxima to connected skeletons. IEEE Trans. Pattern Analysis and Machine Intell. PAMI-3 (March 1981), 134-143. 2. Arcelli, C. A condition for digital points removal. Signal Processing 1, 4 (1979), 283-285. 3. Deutsch, E.S. Thinning algorithms on rectangular, hexagonal, and triangular arrays. Commun. ACM 15, 9 (Sept. 1972), 827-837. 4. Hilditch, C.J. Linear skeletons from square cupboards. In: Machine Intelligence IV, B. Mertzer and D. Michie, Eds., University Press, Edinburgh, 1969, pp. 403-420. 5. Ogawa, H. and Tanguchi, K. Thinning and stroke segmentation for handwritten Chinese character recognition. Pattern Recognition 15, 4 (1982), 299-308. 6. Pavlidis, T. A Flexible Parallel Thinning Algorithm. Proc. IEEE Comput. Soc. Conf. on Pattern Recognition and Image Processing. Aug. 1981, pp. 162-167. March 1984 Volume 27 Number 3 7. Rosenfeld, A. Connectivity in digital picture. J. ACM 17, 1 (Jan. 1971), 146-160. 8. Rosenfeld, A. A characterization of parallel thinning algorithm. Info. Control 29 (Nov. 1975}, 286-291. 9. Rosenfeld, A. and Davis, L.S. A note on thinning• IEEE Trans. Syst. Man Cybern. SMC-6, 3 (March 1976), 226-228. 10. Rutovitz, D. Pattern Recognition. Proc. Royal Statists. Soc. 129, Series A (1966), 504-530. 11. Stefanelli, S. and Rosenfeld, A. Some parallel thinning algorithms for digital picture• J. ACM 18 (April 1971), 255-264. 12. Tamura, H. A comparison of line thinning algorithms from digital geometry viewpoint. Proc. 4th Int. Conf. Pattern Recognition, 1978, pp. 715-719. CR Categories and Subject Descriptors: 1.5.2 [Pattern Recognition[: Design Methodology--pattern analysis; 1.5.4 [Pattern Recognition[: Applications-computer vision General Terms: Algorithms, Theory, Applications Additional Key Words and Phrases: parallel algorithm, thinning of digital patterns, skeletonization Received 3/83; accepted 9/83 Authors' Present Addresses: T. Y• Zhang, Department of Computer Science and Automatic Control, Chongqing University, Chongqing, China; C. Y. Suen, Department of Computer Science, Concordia University, 1455 de Maisonneuve West, Montreal, Quebec H3G 1M8. Canada Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee a n d / o r specific permission. Communications of the A C M 230