A new split-and-merge technique for polygonal approximation of chain coded curves

A new split-and-merge technique for polygonal approximation of chain coded curves

~._N~_.~ February 1995 Pattern Recognition Letters El .SEVIER Pattern RecognitionLetters 16 (1995) 161-169 A new split-and-merge technique for pol...

438KB Sizes 0 Downloads 50 Views

~._N~_.~

February 1995

Pattern Recognition Letters El .SEVIER

Pattern RecognitionLetters 16 (1995) 161-169

A new split-and-merge technique for polygonal approximation of chain coded curves Bimal Kumar Ray, Kumar S. Ray * Electronics & Communication Sciences Unit, Indian Statistical Institute, 203. Barracpore Trunk Road, Calcutta 700035, India

Received 20 September 1993; revised 20 September 1994

Abstract

In all split-and-merge techniques the fundamental problem is the initial segmentation. In this paper the initial segmentation is done by introducing the concept of rank of a point. The split-and-merge is done using two criteria functions, namely, the ratio of the arc length to the length of the line segment and the ratio of the distance from a point to the line segment (not the perpendicular distance) to the length of the line segment. The procedure generates polygons that are insensitive to rotation and scales and remains reliable in presence of noise. Keywords: Rank, Split-and-merge;Invariance; Noise-tolerance

1. Introduction

Polygonal approximation is the approximation of a curve by piece straight line segments. Any curve can be approximated by a polygon with any desired degree of accuracy. A number of algorithms for polygonal approximation of digital curves are already existing. Ramer (1972) and Duda and Hart (1973) introduced an iterative procedure which repeatedly splits the curve into smaller and smaller curve segments until the maximum of the perpendicular distances of the points of the curve from the line joining the initium and the terminus of the curve segment falls within a prespecified value. The curve segments are split at the point most distant from the line segment. Pavlidis and Horowitz (1974) designed a splitand-merge technique which fits lines to an initial segmentation of the boundary and computes the least squares error. The procedure then iteratively splits a * Corresponding author.

line if the error is too large and merges two lines if the error is too small. Some other polygonal approximation algorithms can be found in (Williams, 1978; Wall and Danielsson, 1984; Dunham, 1986; Ray and Ray, 1991, 1992, 1993). Recently, Ansari and Delp ( 1991 ) proposed a split-and-merge technique using Gaussian smoothing. They mention that the fundamental problem in the split-and-merge process is the initial segmentation. The existing split-and-merge process is affected by the initial segmentation. So it is necessary to start with a good set of break-points. They use Gaussian smoothing and take the curvature maxima points as the initial set of break-points and then apply a split-and-merge process. The criterion function used for split-and-merge is the absolute perpendicular distance of the points from the line segment. They show that their approximation is not affected by the initial segmentation. Moreover, Ramer's algorithm (1972) and the split-and-merge process (Pavlidis and Horowitz, 1974) produce polygons that are sensitive to orientation but Ansari and Delp ( 1991 ) show that

0167-8655/95/$09.50 © 1995 ElsevierScienceB.V. All rights reserved SSDI0167-8655(94)00081-6

B.K. Ray, K.S. Ray/Pattern Recognition Letters 16 (1995) 161-169

162

their split-and-merge is less sensitive to orientation though it is scale dependent. They propose another method based on cardinal curvature points which produce break-points that are insensitive to scale. In this paper we propose another split-and-merge process which is insensitive to orientation and scale and is not affected by initial segmentation. This work is prepared with two goals in mind; firstly, to reduce the time complexity with respect to the Ansari-Delp algorithm (1991) and secondly, to make an approximation which is insensitive to orientation and scale but does not destroy the detail of the curve. We also demonstrate the noise tolerance of our procedure.

2. Present technique A closed digital curve Cd is described by a sequence of n integer coordinate points

Cd={p,=(X~,y,), i=1, 2, ..., n} where P,+l is neighbor ofp~ (modulo n). The Freeman chain code of C~ consists of n vectors Ci = P i + 1 Pi

each of which can be represented by an integer fe {0, 1, 2, ..., 7} as shown in Fig. 1 where ¼xfis the angle between the x-axis and the vector. The chain of Cd is defined as {~i, i= 1, 2, ..., n} and c] = c]+,. All integers are in modulo n. Before we present the new technique we define the rank of a point. The smallest angle through which the vector c-~ should be rotated so that c~- and ci+ -~ i have the same direction determines the rank of the point pi and if 0i be the smallest required angle then the rank r~ is given by 3

2

5

6

1

7

Fig. 1. Directions in Freeman chain code.

ri=(4/n)Oi,

i= 1, 2,..., n.

We note that the only possible values for ri are 1, 2, 3 and 4. As already mentioned the fundamental problem in any split-and-merge process is the initial segmentation. In (Pavlidis and Horowitz, 1974) the initial segmentation is done arbitrarily and the approximation depends on the initial segmentation. Ansari and Delp ( 1991 ) use curvature maxima points as the initial set of break-points and show that the initial segmentation does not affect the approximation. They use Gaussian smoothing to locate the curvature maxima points. But Ganssian smoothing increases the time complexity as it involves floating-point arithmetic. We propose to make the initial segmentation on the basis of the rank of a point as already defined. The procedure firstly looks for those points with ri>~3. If there exist at least two such points then these points only comprise the initial set of break-points. But if there exists only one such point then this point together with those with r~= 2 comprise the initial set of break-points. If there exists no such point with r~>i 3 then only those points with r~= 2 comprise the initial set of break-points provided there are at least two points with r~= 2. If there exists only one point with r~=2 then this point together with those with r~= 1 comprise the initial set of break-points. If there exists no point with r~= 2 but there exists at least two points with r,= 1 then these points only comprise the initial set of break-points. One can see that we give priority to those points with high rank. This approach reduces the false choice of the initial break-points. Since the rank is obtained by taking the angular difference between the vectors c, and c~+~ and multiplying it by 4/~, the time complexity for initial segmentation is lower than that of Ansari and Delp ( 1991 ) in which the number of multiplications and additions required depends on the window length of the Gaussian filter. The larger the window length is, the more multiplications and additions are required. Moreover, the Gaussian filter has the effect of shrinking the curve, whereas, our procedure (since it does not need Gaussian smoothing) has no such effect. Using the initial set of break-points we perform a split-and-merge process to make a polygonal approximation of the digital curve. Pavlidis and Horowitz

B.K. Ray, K.S. Ray/Pattern RecognitionLetters 16 (1995) 161-169 (1974) used the perpendicular distance as the criterion function. Ansari and Delp ( 1991 ) too used the perpendicular distance as the criterion function. Consequently, these techniques are scale dependent. Moreover, using the perpendicular distance one may miss some important vertices. As for example, if it be required to check whether the three points A, B and C, where B follows C and A follows B, are collinear (Fig. 2) then using the perpendicular distance of A from the segment BC may lead to an affirmative conclusion, but as evident from the arrangement of the points A, B and C in Fig. 2 the three points are not collinear. So we propose to use the distance of a point to the line segment as the criterion function. The distance to a line segment is computed by the method proposed by Dunham (1986). To compute the distance of the points pk, k = i + l, i+2, . . . , j - 1 from the segment joining the point p~ to pj (Fig. 3) we translate the origin to the point p,- and rotate the segment pipj through an angle 0 and denote the new coordinate system by primes. If x~ lies between 0 and x~ then the distance of the point p~ from p~pj is simply the absolute value of the y-coordinate ofp~. If x~ is negative then the distance ofp~ from p~pj is the dis-

163

tance ofp~ from the origin. If x~ >x~ then the distance ofx~ from the line segment PiPj is the distance ofp~ from the point x~. So for i
fx/(Xk--Xi)2+ (yk--y,) 2, i f x ~ < 0 , d k o = ~ / (Xk--Xj)2 + (yk--yj) 2, ifx~>x~, (lYZI,

if0
But this distance is scale dependent. In order to make it free from scale factor we normalize it by dividing this distance by the length of the segment PiPj which we propose to denote by l0 and is given by l o = x / ( x j - x, )2 + (yj - y Y

.

So the criterion function used is the ratio of dko to l~j, i.e., dku/lo. Curve segments are split at those points where dkJlq is a maximum. Besides this criterion function we use two other criterion functions namely, ( 1 ) the ratio of the arc length (aij) to the length of the line segment (l~j), where a~j is computed by j--i

ao =

x/(x,+,-xY+ l= 1

(y;+,-yy,

(2) the sum ofdko/lo, i.e., j--I

A

~

f

Z

c

(dkijlij).

k=i+l

L.--~

o B Fig. 2. Differencebetweenthe perpendiculardistanceof the point A from the line segmentBC and the distanceof A from the line segmentBC. AD is the perpendiculardistanceand AB is the distanee to the line segmentBC.

v,.

/

In order to avoid unnecessary computation of dkoIlo, we introduce aoll U. Comparing this function with a prespecified value we can conclude whether the points Pk (i< k
//

i

I! I I I I

t~

L

0

i

PL

,s

Fig. 3. Geometrical interpretation of computation of the distance to the line segment.

i

g'

B.K. Ray, K.S. Ray/Pattern Recognition Letters 16 (1995) 161-169

164

ear then only we compute the criterion function dko/ 1o. We take 1.1 (Pavlidis, 1982) as the prespecified value of a J la. I f

j--I k=i+

(dk,jll~j)

<

1.2

1

but

aiJl o > 1.1 then the points may or may not be collinear. In this case we compute j--I

Y~ (dk,dlo)

kffii+l

and compare it with a prespecified value which we choose as 1.2 on the basis of a trial-and-error process. Even when aij/lii> 1.1 and the sum Y~{-~+~(dki;/la) does not exceed 1.2 but

max (dk~fllo) >-0.40 k then also the point B should be retained as a breakpoint. The procedure of splitting and merging are continued till no new break-point is generated in the splitting process and no break-point is removed during the merging process. One may note that we have used two thresholds namely, 1.2 and 0.40 on j--I

max ( dko/ lo ) >t 0.40 k (obtained on the basis of a trial-and-error process) then also the curve segment is split at the point Pk where maXk(dko/Iu) occurs. When all necessary splittings are done the merging is performed in the following manner. For every three break-points A, B and C obtained from the splitting stage, we compute la=AC and a o = A B + B C . If

(dkiJlij)

k

respectively. Apart from these values ( 1.2 and 0.40) we have tried with some other values of these parameters, e.g. j--I

1.0 and 1.1

for

1

and 0.2 and 0.3

for max (dka/la) k

then the break-point B is removed from the set of break-points. But if

ao/l a > 1.1 then we compute dk~j/l~j for every point Pk intermediate of A and C. If j--1 <

1.2

k= i+ 1

but the approximations are found to be insensitive to these changes of the parameters. For tolerance greater than 1.2 on y~-l/+ 1(dka/lo) and greater than 0.40 on maxk (dka/lO), the basic shape of a curve is destroyed.

3. Procedure: split-and-merge

Step 1: Splitting. If ao/l o > 1.1

and

then compute

max (dko/lij) <0.40 k

j--I

E

then the point B is removed from the set of breakpoints. If

(dkiJlifl

k~i+l

else if j-l

j--I

~, k=i+

(dko/lij)

~ k=i+

aalo
~, (dkij/lij)

max (d~a/lo) ,

and

k=i+l

(dko/lo) > 1.2 l

then the point B should be retained as a break-point. If

Y~ (dkjto)/> 1.2 k= i+ 1

then split the curve segment between i and j at the point Pk at which dko/lo is a maximum

B.K. Ray, K.S. Ray/Pattern Recognition Letters 16 (1995) 161-169

165

max (dku/lu) >/0.40 then split the curve segment at the point where dku/ l a is a maximum else splitting is not necessary.

Step 2: Merging. For every three consecutive breakpo__iintsA, B and C (say), compute ao/l u where l a =

AC.

If

aa/ lij < 1.1 (a)

then merge the break-point B else if

(b)

Fig. 4. A leaf shaped curve. (a) Digital version. (b) Polygonal approximation.

au/l u > 1.1 and

else if j--I

Z

k= i + 1

j--I

(dmjllij)

i+1

< 1.2

(dkifl~j) < 1.2

but and

max (d~u/lu) < 0 . 4 0 k

..'"

°,,

"'"°°..•..

..:,

°..°..'°"•

(a) °. "',

}

,°° ""

, .....

". . . . . . ;i

°

°*: :",,

) (a)

. :.... . ........

,

: ,

,

(b~

Fig. 5. A screwdriver• (a) Digital version. (b) Polygonal approximation.

(b) Fig. 6. A circle• (a) Digital version. (b) Polygonalapproximation.

166

B.K. Ray, K.S. Ray/Pattern Recognition Letters 16 (1995) 161-169

4. Experimental results

then merge the break-point B else merging is not possible. Step 3. Repeat Step l and Step 2 until no more split-

ting and merging is possible.

e :20 °

We have applied our procedure on three digital curves namely, a leaf shaped curve (Fig. 4) taken from (Rosenfeld and Johnstone, 1973), a screwdriver (Fig. 5 ) and a circle (Fig. 6) taken from (Medioni and Yasumoto, 1987). Figs. 4(b), 5(b) and 6(b) show their polygonal approximations. Fig. 4 is

e : 30 ° B : 60 °

e :10°

g :/,0 °

o : 70 °

e:50 °

: 80 °

Fig. 7. Polygonalapproximationof the leafshaped curveat differentorientationsO.

B.K. Ray, K.S. Ray/Pattern Recognition Letters 16 (1995) 161-169

S :1.2

s=k6

s :1.4

s=1.8

167

s=2.0

Fig. 8. Polygonal approximation of the leaf shaped curve at variables scales s.

168

B.K. Ray, K.S. Ray/Pattern Recognition Letters 16 (1995) 161-169

of 10 °. This process of generating the data does not necessarily produce uniformly spaced points from a data set of uniformly spaced points. Sometimes the data points may become non-uniformly spaced. In order to make the points uniformly spaced we use linear interpolation. The data points at variable scales are generated using the transformation rules

.i

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

!

,,

....

.".

.

x'=sx

and

y'=sy,

s>0.

Each point of the digital curve is subjected to these transformation rules and the corresponding point (x~, y~) is generated by rounding x'=sx

(

L

Cb)

Fig. 9. A noisy cross. (a) Digital version. (b) Polygonal approximation. an example of a curve which has more than two points with rank 3 or 4, Fig. 5 is an example of a curve with a single point having rank 2, and Fig. 6 is an example of a curve that has more than two points with rank 2. To show that our procedure generates a polygon that remains invariant with respect to orientations, we generate the data at different orientations using the transformation rules

and

y'=sy

to the nearest integer. The scale parameter s is varied from 1.0 to 2.0 and is sampled at an interval of 0.2. This process of generating the data points does not necessarily produce uniformly spaced points from a data set of uniformly spaced points. We make the points uniformly spaced using linear interpolation. Fig. 7 shows the polygonal approximation of the leaf shaped curve at different orientations and Fig. 8 shows the polygonal approximation of the same curve at variable scales. The vertices of the polygon at different orientations and scales differ in their absolute position by at most two pixels and the number of vertices at different orientations and scales is not different. To show the noise tolerance of our procedure we have applied it on a noisy cross (Fig. 9 ( a ) ) taken from (Ansari and Huang, 1991 ). Fig. 9(b) shows its approximation. One can see how smooth the polygon is. No noisy point appears as a vertex and no true vertex is missed.

x ' = x cos O - y sin O, 5. Conclusion

y ' = x sin O+y cos O.

Each point p~(xi, y~) of the digital curve is subjected to these transformation rules and the corresponding point (x~, y~) at the orientation 0 is generated by rounding Xi COS O--y i sin 0 and

xt sin O+y~ cos 0

to the nearest integer. The orientation parameter 0 is varied from 0 ° to 90 ° and is sampled at an interval

The existing split-and-merge procedure generates a polygon which is affected by initial segmentation and sensitive to orientation and scale. The curvature guided polygonal approximation proposed by Ansari and Delp ( 1991 ) is less sensitive to orientation but is scale dependent. The cardinal curvature points are insensitive to scale but destroy the detail of the curve.

B.K. Ray, K.S. Ray/Pattern Recognition Letters 16 (1995) 161-169

O u r p r o p o s e d split-and-merge technique is insensitive to orientations as well as scales a n d it does not destroy the detail o f the curve. Since the initial segm e n t a t i o n technique is simple, it is c o m p u t a t i o n a l l y less expensive than that proposed by Ansari and Delp which uses G a u s s i a n smoothing which apart from its effect o f shrinking the curve has high c o m p u t a t i o n a l load. O u r procedure remains reliable even in presence o f noise.

References Ansari, N. and E.J. Delp ( 1991 ). On detecting dominant points. Pattern Recognition. 24, 441-450. Ansari, N. and K.W. Huang (1991). Non-parametric dominant point detection. Pattern Recognition 24, 849-862. Duda, R.D. and P.E. Hart (1973). Pattern Classification and Scene Analysis. Wiley, New York, 328-339. Dunham, J.G. (1986). Optimum uniform piecewise linear approximation of planar curves. IEEE Trans. Pattern Anal. Machine Intell. 8, 67-75. Medioni G. and Y. Yasumoto ( 1987 ). Comer detection and curve

169

representation using cubic B-splines. Computer Vision, Graphics, and Image Processing39, 267-278. Pavlidis, T. (1982). Algorithms for Graphics and Image Processing. Computer Science Press, New York, 281-297. Pavlidis, T. and S.L. Horowitz (1974). Segmentation of plane curves. IEEE Trans. Comput. 23, 860-870. Ramer, U. (1972). An iterative procedure for polygonal approximation of plane curves. ComputerGraphicsand Image Processing 1,244-256. Ray, B.K. and K.S. Ray (1991). A new approach to polygonal approximation. PatternRecognition Lett. 12, 229-234. Ray, B.K. and K.S. Ray (1992). An algorithm for polygonal approximation of digitized curves. Pattern Recognition Lett. 13, 489-496. Ray, B.K. and K.S. Ray (1993). An optimal algorithm for polygonal approximation of digital curves using L~ norm. Pattern Recognition 26, 505-509. Rosenfeld, A. and E. Johnston (1973). Angle detection on digital curves. IEEE Trans. Comput. 22, 875-878. Wall, K. and P.-E. Danielsson (1984). A fast sequential method for polygonal approximation of digitized curves. Computer Vision, Graphics, and Image Processing28, 220-227. Williams, C.M. ( 1978 ). An efficient algorithm for piecewiselinear approximation of planar curves. Computer Graphics and Images Processing8,286-293.