A Fast Parallel Algorithm For Thinning Digital Patterns: T. Y. Zhang and C. Y. Suen
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.
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
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
P, (i- 1, j- 1) P,
(i, j -
P2 (i- 1, j)
P1 (i, j)
P3 (i- 1, j+ 1)
1)
P,
(i,j+
1)
P~
Pe
Ps
(i+ 1 , j - 1)
(i+ 1,j)
(i+ 1,j+ 1)
236
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. 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 :
0
i
0
: P~
I
0
I
\2 J
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
FIGURE 2. Counting the 01 patterns in the ordered set P2, P~, P4, .... P~, P~. North P2
B(Pi)
t h a t is,
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
P1,
West
Pa
Pl Pa South
P4
East
A(Pi) = 2
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@@.
@@8@~@@8. @@8@@8@@. ~8@@8@@@.
@ @ @ @ . @ @ @ @
8@~@@@@@. @@~@@88@. @ @ @ @ . @ @ @ @
.@88@8@@
.@8@@@88 .88888@~ .8@@@@@@
. . . . . . . . . . . . . . . .
@ ~o @. @.
.'. . . ..
. .. ..
.@
. . . .
o@., .@ . . . .
@ . . . . @ . . . .
@o
. . . . . . . . . . . . . .
8~8@@@@@. @ @ @ @ . @ @ @ @ ~@#@@@#.
o . . . . . . . .
@@8@@@#8. #@#@@088. @ @ @ @ . @ @ @ @
o . . . . . .
. @ @ @ 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@@.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . .
. . . . .
. . . . .
(a)
(b)
(c)
237
Research Contributions
(c) (d)
P2*P4*P6 = 0 P4*P6*P8 = 0
(1) (2)
0 O-0 0 1
0 ~ 0
I
0
I
i
I
1
I
1 1 0 ~ 0
I
1 1
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
;
0
O.
I
0
Start
C=O
C = C+l, ifM(i,j) = 1
IT = IT - M
Yes
C=O
IT = IT - M
TABLE I. Comparison of CPU Time (in seconds) Consumed by Different Parallel Thinning Algorithms Pattern B ~ Movingbody Method Four-Step 0.765 1.031 2.713 Two-Step 0.678 0.882 2.221 Our Algorithm 0.454 0.505 1.163
Yes
238
Research Contributions
. .
. .
..,.--
...
......
.....
@ ........
@@..
. ~
,i .......
~i
..... ; ............
iii
1,2
*,,;;'. '~,2
.H,,,,
.....
ottt ....
...... "" i ; . . . . .
~2j,~ ~ .... ~
222,1
~.2.
..,. .... .
..............
~e . . . . . . . . . .
.* ........
"~;;22
..~...
::~;:::: (c)
(a)
(b)
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
Communications of the A C M
230