A new approach to polygonal approximation

A new approach to polygonal approximation

Pattern Recognition Letters 12 (1991) 229-234 North-Holland April 1991 A new approach to polygonal approximation Bimal Kr. Ray and Kumar S. Ray* Ele...

346KB Sizes 1 Downloads 126 Views

Pattern Recognition Letters 12 (1991) 229-234 North-Holland

April 1991

A new approach to polygonal approximation Bimal Kr. Ray and Kumar S. Ray* Electronics & Communication Sciences Unit, Indian Statistical Institute, 203 B.T. Road, Calcutta-700035, India

Received 24 October 1990

Abstract

Ray, B.K. and K.S. Ray, A new approach to polygonal approximation, Pattern Recognition Letters 12 (1991) 229-234. A new technique for polygonal approximation is proposed. It is fast and simple. The vertices of the polygon are identified by considering the patterns exhibited by the first-order finite differences of boundary point data. The error of approximation in constructing the polygon is found to be within a certain bound. Keywords. Polygonal approximation.

Introduction This paper deals with polygonal approximation of the boundary of two dimensional (2-D) objects. By polygonal approximation of the image boundary we mean the approximation of the boundary curve (plane curve) by segments of straight lines. When the analytic form of the boundary curve is known, to find a polygonal approximation, the sum of the squares of errors between the curve and the polygon is minimized and the breakpoints are found (Pavlidis, 1977a). In pattern recognition and in object recognition, the equation of the boundary curve of the object is entirely unknown. But the boundary of the object has been digitized and the boundary points are given by their positional coordinates with respect to a chosen set of rectangular axes. In polygonal approximation the bound-

* Current address: Electrical & Computer Engineering Dept., ENS 520, The University of Texas at Austin, Austin, TX 78712-1084, USA.

ary point data are grouped into line segments using a smoothing technique such as the split-and-merge technique, linear scan technique etc. (Pavlidis and Horowitz, 1974; Pavlidis, 1973, 1982). These techniques and their variants are well described in (Pavlidis, 1977b, 1982). In this letter we present a new technique of polygonal approximation which utilizes some results of numerical analysis and some concepts of regression analysis. Here we find out the first-order finite differences of the abscisae (x) and the ordinates (y) of the data points which have been obtained by digitizing the object boundary on a rectangular grid. Then we try to identify some patterns (described later) in the first-order finite differences Ax and A y. By recognizing these patterns we find out the sides of the polygon approxiinating the object boundary. In polygon-fitting algorithms the data points are subdivided into groups. Each group of points is approximated by a side of the polygon. In our approach, the finite differences Ax and A y themselves subdivide the data points according to the

0167-8655/91/$03.50 © 1991 -- Elsevier Science Publishers B.V. (North-Holland)

229

Volume 12, Number 4

PATTERN RECOGNITION LETTERS

April 1991

patterns observed in the successive values of Ax and d y. All we have to do is to locate the breakpoints and join them by straight line segments. The breakpoints can be located by reading the differences d x and A y.

of edges it posseses, this polygon is usually approximated using a smoothing technique. Our polygonal approximation, too, involves a smoothing technique which is based on the following proposition from numerical analysis and some concepts of regression analysis.

2. Pattern recognition of finite differences

Proposition 1.0 (Scarbourough, 1930). I f the nth differences o f a tabulated function are constant when the values o f the independent variable are taken in arithmatic progression, then the function is a polynomial o f degree n.

We start with the boundary data points (xi, Yi) which have been obtained by digitizing the continuous boundary of the objects. Thus we have a discrete planar curve

c(d) =

{(xi,y;) I l <~i<~n}

where n is the number of distinct points of the curve. If the curve is open, the last point (x,,,y,,) is distinct from the first point (x~,y0. But if it is closed, then the last point is (x,,+l,Y,l+0 and it coincides with (xl,Yl). We assume that the arrays xi, yi are known to the system. From these arrays we construct the first-order finite differences Axi and A Yi. These differences take values 0, 1 and - 1 only. The successive differences, as we go through them exhibit the following patterns. (a) Axi's are constant for a series of equidistant values of y. (b) d yi's are constant for a series of equidistant values of x. (c) Axi's take values 0 and 1 only for a series of equidistant values of y. (d) dxi's take values 0 and - 1 only for a series o f equidistant values of y. (e) A Yi'S take values 0 and 1 only for a series o f equidistant values of x. (f) d yi's take values 0 and - 1 only for a series o f equidistant values of x.

3. Basic results and concepts The polygon representation of the shape of the boundary of an object can be obtained by using any boundary tracking algorithm. It is not uncommon that such a representation involves a polygon having too many edges. Since the time required for processing the polygon is dependent on the number

230

Besides the above proposition of numerical analysis we use some concepts of regression analysis. In regression analysis the scatter diagram of bivariate data exhibits either a linear tendency or a curvilinear tendency. Either the points of the scatter diagram exhibit that there is a tendency in them to cluster around a straight line or they exhibit the tendency of clustering around a curve (curvilinear tendency), provided the variables are related. If the points of the scatter diagram exhibit a linear tendency, then we can find a linear relationship between the variables, i.e., the points can be approximated by a straight line. In regression analysis this line is the least square line. In our smoothing technique we have exploited the above concepts without using least square line.

4. Smoothing technique The smoothing technique involves reading the first-order finite differences Axi and A Yi, locating the breakpoints and joining the successive breakpoints by straight line segments. In this section we describe how to perform the smoothing technique so as to locate the breakpoints. Following the proposition stated in the last section, the series of successive points where the pattern (a) is observed can be smoothed out by a single straight line segment which we find out by joining the end points of the series. The series o f successive points revealing pattern (b) can similarly be smoothed out following the same proposition.

Volume 12, Number 4

PATTERN RECOGNITION LETTERS

When a series of successive points reveal pattern (a) or pattern (b) and the points are approximated by a straight line segment, the error of approximation is zero, i.e., each and every point of the series is contained on the straight line. The series of successive points revealing the pattern (c) exhibit that there is a tendency in the points to cluster near a straight line. Hence from the concepts of regression analysis stated in the last section, we can smooth out these points by a straight line segment. The straight line segment that we use in our technique is not the least square line. The use o f least square line sometimes leads to an unconnected boundary, since the estimated line does not necessarily have to go through any of the points on the boundary. The straight line segment that is used to smooth out these points is obtained by joining the end points of the series revealing pattern (c). The series of successive points revealing pattern (d), (e) or (f) are similarly smoothed out by a straight line segment. When a series of successive points reveal pattern (c), (d), (e) or (f) and the points are approximated by a straight line segment, the error of approximation is non-zero. But this error is always within a certain bound. We propose to measure this error by the ratio of arc length (L a) to the length of line segment (L). Thus if a series of successive points (xi, Yi) for i = j , j + 1..... k exhibit pattern (c), (d), (e) or (f), then La--"

k E [(Xi-Xi-l)2+(Yi-Yi-l)2] 1/2 i=j+l

and

L = [(xj --Xk) 2 + (yj --yk)2] I/2 and the error of approximation is proposed to be measured by La/L. We have experimented with different types of digitized planar curves and have found that the ratio La/L is always within 1.1. Hence our approximation technique is acceptable (Pavlidis, 1982).

April 1991

up in the last sections. The implementation has been presented in the form of the 'Algorithm FindThe-Vertex'. The algorithm scans along the finite differences and locates the vertex. From Step 1 to Step 8 the algorithm finds out the finite differences A x and A y from the input boundary point data xi, Y;. From Step 9 to the last step the algorithm scans along the finite differences to locate those breakpoints where any one of the six patterns (a) to (f) as described in Section 2 is exhibited. To identify those points where pattern (a) or (b) is exhibited we have introduced two counters, namely, c~ and ¢2. To characterize the constancy of A x for equidistant values of y or of d y for equidistant values of x we have set up the critical values of cl and c2 to be 4. Thus if at least four successive differences d x or A y are constant for equidistant values of y or x respectively, then we identify pattern (a) or (b). This task is performed in Step 13 to Step 18 of the algorithm. As we perform this task those points where d x takes values 0, 1 and - 1 (not constant in the sense already described) for equidistant values of y and those points where d y takes values 0, I and - 1 for equidistant values of x, are automatically identified. To separate the variation 0 and 1 from 0 and - l we have kept the track of the sign of A x and d y. Whenever, A x or A y changes sign a new vertex is identified (if it is not already found in the previous steps). This task is performed in Steps 11, 12 and from Step 19 to Step 28. To avoid multiple occurrence of a single vertex we have introduced the variable last i. This variable name will check whether a particular vertex has already been obtained. This task has been performed in Steps 15, 18, 24 and 27. The 'Algorithm Find-The-Vertex' finds only the vertices of the polygon but it does not find the polygon. To find the polygon we have constructed the 'Algorithm Polygonal Fit'. This algorithm finds the line joining two successive vertices which we propose to designate by xj, yj and xj+l, Yj+I" The line is designated by L(j) and is defined by

x(yj-Yj+l)+ y(xy+l-Xj)+Yy+l~3"-yjXj+ 1 = O. 5. Scan-along implementation 6. Algorithm Find-The-Vertex We have made a scan-along implementation of the concepts and the technique that we have built

Comments. The input of this algorithm are the 231

Volume 12, Number 4

PATTERN RECOGNITION LETTERS

boundary point data xi, Yi which we assume to be known to the system. The output of the algorithm are the vertices of the polygon. The vertices can be joined in order to form the polygon.

Step Step Step Step Step Step

1. 2. 3. 4. 5. 6.

Set i = 1. If i <~n + l then read xi, Yi. Replace i by i + 1. Go to Step 2. Else go to Step 5. Set i = I. If i<~n then evaluate

Axi=xi+ I - X i, A yi=Yi+l-Yi. Step 7. Step 8. Step 9. Step 10. Step 11. Step 12. Step 13. Step 14. Step 15. Step 16. Step 17. Step 18.

Step 19. Step 20. Step 21. Step 22. Step 23. Step 24.

Step 25.

232

Replace i by i + 1. Go to Step 6. Else go to Step 9. Set i = 1 , C l = l , c2=1, dXo=dXn, AYo= A yn, j = l , u ( j ) = 0 , o ( j ) = 0 , last i=O. While i<<.n do: Begin If Axi--#O then go to Step 19. If Ayi*:O then go to Step 21. If Axi=Axi_ I then set C l = C l + l . Go to Step 16. If c~/>4 then go to Step 15. Else set c~ = 1. Go to Step 16. If last i= i - c l then write xi, Yi and xi-¢,, Yi- c,. Set last i = i. If A y~ = A y~_ ~ then set c2 = e2 + 1. Replace i by i + 1. Go to Step 10. If c2>~4 then go to Step 18. Else set c2 = 1. Replace i by i + 1. Go to Step 10. If last i = i - c2 then write xi, Yi. Else write xi, Yi and xi-o, Yi-~. Set lasti=i. Replace i by i + 1. Go to Step 10. If uj+dxi=O then go to Step 23. If uj + d x i = +1 then s e t j = j + 1, uj = dxi. Go to Step 12. Else go to Step 12. If o)+ d Yi = 0 then go to Step 26. If o j + d y i = + l then set j = j + l , oj= A yi. Go to Step 13. Else go to Step 13. If c ~ > l then go to Step 24. Else go to Step 25. If l a s t i = i - q then write xi, Yi else write xi, Yi and xi-c,, Yi-¢~. Set last i=i, j = j + 1, u j = d x i . Go to Step 12. Write x~, y;. Set lasti=i, j = j + l , Uy= Ax u Go to Step 12.

April 1991

Step 26. If c2>1 then go to Step 27. Else go to Step 28.

Step 27. If last i = i - c2 then write xi, Yi else write xi, Yi and xi-c:, Yi-c2. Set last i = i - c 2 , j = j + 1, oj=A Yi. Go to Step 13. Step 28. Write xi, Yi. Set last i = i, j =j + 1, oj = d Yi. Go to Step 13. End.

Step 29. End of algorithm.

Algorithm Polygonal Fit Comments. We propose to designate the input array of this algorithm by xj, yj which are the output of the Algorithm Find-The-Vertex. The successive values of xj, yj are in the same order as they are obtained from the Algorithm Find-The-Vertex. The successive values o f j stand for the successive vertices. The number of vertices is denoted by n.

Step 1. Read xj, yj for j = 1 to n. Step 2. Set xn+l =xl, Yn+l =Yl, J = I. Step 3. While j<~n do: Begin

Step 4. Evaluate aj=yj-yj+l, bj = xj + l - xj,

cj=Yj+IXj--yjxj+I. Step 5. Draw the line L ( j ) described by the coefficients aj, bj and cj. Step 6. Replace j by j + 1. Go to Step 3. End

Step 7. End of algorithm.

7. Time complexity To find the time complexity of the Algorithm Find-The-Vertex, we note that this algorithm is partly numerical but mostly non-numerical. It involves more comparisons than arithmetic operations. As we run through this algorithm we find that at Step 6 we need two subtractions for each value of i. Hence as i runs from 1 to n we need a total of 2n subtractions. Most of the time of execution of this algorithm is spent at Steps 11, 12, 13 and 16. At Steps 11 and 12 we need one comparison each for each value of i. Hence we need a total of 2n comparisons. At

Volume 12, Number 4

April 1991

PATTERN RECOGNITION LETTERS

Steps 13 and 16 we need a total of 2n comparisons. Thus the time complexity of this algorithm is O(n). Therefore the algorithm is fast. The Algorithm Polygonal Fit is mostly numerical. As we run through this algorithm we find that at Step 4 for each value o f j we need three subtractions and two multiplications. Hence this algorithm requires a total of 3n subtractions and 2n multiplications. And therefore the time complexity of this algorithm is O(n).

Figure 2. A wrench image.

8. Experimental results We have applied our polygonal approximation on three images namely, a plier, a wrench and an overlapping image. The continuous boundaries of these images are shown in Figures 1-3. These continuous boundaries have been digitized on a rectangular grid and the boundary point data have been used for the approximation. The polygonal approximations of the three images are shown in Figures 4-6.

Figure 3. An overlapping image.

9. Conclusion We have devised a new technique of polygonal approximation which is simple and fast. The technique has been applied on a number of images and we have obtained very promising results. This tech-

Figure 4. Polygonal approximation of plier image.

Figure 1. A plier image.

Figure 5. Polygonal approximation of wrench image. 233

Volume 12, Number 4

PAI'TERN RECOGNITION LETTERS

April 1991

s u b d i v i d e the b o u n d a r y p o i n t d a t a to f o r m a p o l y g o n . T h u s we d o not have to p r o c e e d with a trial a n d e r r o r process for finding the p o l y g o n .

References

Figure 6. Polygonal approximation of lhe overlapping image.

nique always produces a completely connected b o u n d a r y which is very m u c h necessary for o b j e c t r e c o g n i t i o n . T h e most i m p o r t a n t aspect o f this t e c h n i q u e is that the finite differences themselves

234

Pavlidis, T. (1973). Piecewise approximation of plane curves. Proc. 1st Intl. Joint Conf. o f Pattern Recognition, October 30-November I, 1973, 396-405. Pavlidis, T. (1977a). Polygonal approximations by Newton's method. IEEE Trans. Computers 26 (8), 800-807. Pavlidis, T. (1977b). Structural Pattern Recognition, Springer, New York. Pavlidis, T. (1982). Algorithms for Graphics and Image Processing. Computer Science Press, Rockviile, MD. Pavlidis, T. and S. Horowitz (1974). Segmentation of plane curves. IEEE Trans. Compuwrs 23 (8), 860-870. Scarbourough, J. 0930). Numerical Mathematical Analysis. Oxford and IBH Publ. Co.