May 1995
Pattern. Recognition Letters ELSEVIER
Pattern Recognition Letters 16 (1995) 543-548
The linear time recognition of digital arcs Peter Damaschke Fern Universitiit, Theoretische lnformatik I1, 58084 Hagen, Germany
Received 21 August 1994; revised II November 1994
Abstract
We present a linear-time algorithm for recognizing digitized circular arcs, by a reduction to linear programming in fixed dimensions. This generalizes the known results for both digital line segments and complete circles. Moreover, our idea is flexible enough to admit further extensions, such as recognizing disconnected subsets of digital circles and ellip!ical arcs. Keywords: Digital arcs; Circles and ellipses; Linear programming; Halfspace intersection; Linear time recognition algorithm
1. Introduction
The recognition of digitized geometric objects is an important problem in image analysis. Linear-time recognition algorithms are known for digital line segments, cf. e.g. (Creutzburg et al., 1982; Anderson and Kim, 1985), and for complete digital circles (Sauer, 1993). A recognition method for circular arcs was proposed in (Kovalesky, 1990), but it does not immediately lead to a linear algorithm. In this paper we present a linear algorithm for recognizing digital circular arcs, thus in some sense generalizing both mentioned results. (Note that any digital line segment is also a digital arc with sufficiently large radius.) This generalization is not obvious. (Sauer, 1993) makes use of the minimum covering circle algorithm from (Megiddo, 1983), but this is not appropriate if also partial circles shall be recognized. Clearly, the minimum circle around a digitized arc is not necessarily related to a circle from which the given pixei set is the digitalization. So we follow another idea: We solve the problem by a direct reduction to linear
programming in fixed-dimensional space, without detour via some further problem. An advantage of our approach is that it allows further generalizations, in contrast to the earlier algorithms which are designed only for the respective special classes of figures. E.g. we can drop the demand that the arc is connected, and we Can similarly recognize also partial ellipses. But then some additional difficulties can occur, and we do not know whether linear time is reachable. We will briefly discuss this in the last section. We remark that our question is quite different from arc fitting for a noisy digital curve, such as studied in (Landau, 1987; Thomas and Chart, 1989). Nevertheless one may ask for advisable r~laxations of our method which tolerate noise, but this is not the topic of this paper and of the previous works mentioned above. First we solve a somewhat restricted problem which nevertheless already contains the core of the problem: Decide in linear time whether a given 8-connected digital curve with at most one pixel on each vertical line (that is, a digital function curve) is
0167-8655/95/$09.50 © 1995 Elsevier Science B.V. All rights reserved SSDI 0167-8655(95)00127-8
P. Damaschke / Pattern Recognition Letters 16 (1995) 543-548
544
a digital circular arc. Since one can easily divide an arbitrary digital curve - even if it is given as an unordered set of pixels - into such function curves (with x or y as the independent variable) and assign them to the northern, eastern, southern, and western quarter of a circle, we will also recognize arbitrary digital circular arcs.
2. Digitalization of curves
A pixel is a point in the plane with integer coordinates. That means, we use the term pixel synonymously with point of the grid. The grid which is used may be coarser than the resolution of a given real-world image. The 8-neighbors of a pixel ( p , q) are the eight pixels whose abscissa and ordinates differ from p and q, respectively, by at most 1. A digital curve is a sequence of pixels such that neighbored pixels in the sequence are also 8-neighbors. A set P of pixels is 8-connected if each pixel of P can be reached from each other pixel of P on a digital curve entirely passing in P. A set of pixels is called a digital function curve if it is 8-connected and contains for each abscissa p at most one pixel ( p , q). For a continuous curve C in the plane, the digitalization dig(C) of C is the set of all pixels ( p , q) such that there exists a point (x, y) ~ C with (V) q - 7 <1 y < ~ q + ~
1
and
p=x,
1
1
and
q=y.
(H) p - 7 < x < ~ p +
7
or
We will refer to (V) and (H) as the digitalization conditions; V and H stand for "vertical" and "horizontal". In (Sauer, 1993) the same definition was presumed; it is also essentially equivalent to the digitalization schemes in (Kovalesky, 1990), despite of the different formulation. Let F be the graph of a differentiable function f in some open interval 1, such that - 1 < f ' ( x ) < 1 for all x ~ I . Let D be the set of pixels ( p , q) dig(F) satisfying p ~ I. (At most two pixels from dig(F) violate this condition.) L e m m a 1. We have ( p , q ) E D
if and only if q 1 < f ( p ) < ~ q + ~, that is, if (V) is satisfied. Consequently, D is a digital function curve on interval I.
Proof. q - 7, < f ( p ) ~ q + 71 is equivalent to: p ~ I, and ( p , q) fulfills (V). Hence it implies (p, q) ~ D. Conversely assume ( p , q ) ~ D . Then we have particularly p ~ 1. If ( p , q) satisfies (V) then the 1 1 above equivalence shows q - 7 < f ( P ) ~< q + 7. So assume that ( p , q) satisfies (H). Then there exists a 1 1 point (x, q ) ~ F such that p - 7 < x < ~ p + 7. But since - 1 < f ' ( x ) < 1 holds for x ~ I, one immediately sees that ( p , q) also fulfills (V): choose x = p and y = f ( p ) . Now it is clear that D contains for each abscissa p ~ I at most one pixel ( p , q), and from - 1 < f ' ( x ) < 1 we obtain that ( p , q), ( p + 1, q l ) ~ D always implies that ql - q is - 1 , 0, or 1. [] L e m m a 2. Let C be the graph of a continuous function in some interval, and suppose that D = dig(C) is a digital function curve. Then all pixels of D, possibly except the leftmost and rightmost one, satisfy (V).
This is clear from a simple observation: Since C is connected, it meets all vertical lines through the inner pixels of D, thus the lemma follows immediately. Note carefully that we need the assumption that D is the entire digitalization of C; the weaker assumption D ___dig(C) would not be sufficient here.
3. Halfspace intersection
As a further preparation we need the intersection of halfspaces in d-dimensional space ~ d where d is fixed. A halfspace H is a region of the space bounded by a (d - 1)-dimensional hyperplane h, belonging or not belonging itself to H. If h c H then H is called a closed halfspace; if h n H = ~t then H is called an open halfspace. A linear program in d variables is a set of n closed halfspaces, called the constraints, together with a linear function f: ~d ___>R1, called the objective function. The aim is to find a point x in the intersection S* of all constraints, such that f ( x ) becomes minimal. It is well known (Dyer, 1984; Megiddo, 1983, 1984) that linear programming in a space with fixed dimensions can be executed in O(n) time.
P. Damaschke / Panern Recognition Letters 16 (1995) 543-548
If a linear program has no solution then either S* = ¢ or f is downwards unbounded on S*. This alternative can also be decided in O(n) time as follows. Solve the linear program on S * with the opposite objective function - f . If there is a solution then we have trivially S * ~ 0. If there is no solution then either S* = ¢ or both f and - f are unbounded on S *. In the latter case, S* meets every hyperplane h standing orthogonally to the gradient of f. Now add a further constraint H, bounded by an arbitrary such h, to the problem. Then we have clearly S * 4: ~t if and only if this extended linear program with f or - f has a solution. Let us summarize: One can decide in O(n) time whether a set of n closed halfspaces has a nonempty intersection S*, and in this case one can also report some point of S*. From this we conclude a theorem which is certainly of independent interest.
Theorem 1. Given a set of n (open and~or closed) halfspaces in d-dimensional space ( d fixed), one can decide in O(n) time whether their intersection is nonempty. Proof. The problem is now that also open halfspaces are allowed. So a single application of linear programming as above is not sufficient, instead we have to execute an iterative process. Let OPEN denote the set of all hyperplanes bounding the given open halfspaces. Let S and S* be the intersection of the given halfspaces and of their closures, respectively. Note that S can be obtained from S* by removing the union of all h ~ OPEN. Executing linear programming on S* with an arbitrary objective function, we either find a point of S* or we get S ~ = 0, hence S = ~l. As an induction hypothesis we assume for some k with l ~ < k ~ < d that we know k points from S* being the vertices of a ( k - 1)-dimensional simplex Tk. We have already found T1, namely a single point from S*. Note Tk c_ S*, since S* is convex. By O(kdn) arithmetic operations we can check whether there is a hyperplane h ~ OPEN containing all vertices of T~. Case 1: No such h exists. If k - - 1 then this immediately implies T 1 c S, thus we know S 4: ~I. For k > I we claim: No interior point of Tk can
545
belong to some hyperplane h ~ OPEN. Otherwise we would have either Tk c h or h would separate some vertices of Tk from each other. The former subcase contradicts the assumption of Case 1. The latter subcase is also contradictory, since Tkc_iS* lies completely on one side of h. Hence the interior points of Tk belong to S which shows S 4: ~t. Case 2: There exists a hyperplane h ~ OPEN such that Tk c h. Then solve the linear program on S * with an objective function which is iderltically 0 at h and negative in H. If the minimum value is 0 then it follows S * ___h, thus we know S = ~. Otherwise (the minimum is negative or the function is unbounded) we find a further point of S * outside h. Together with the vertices of Tk it forms the vertex set of a larger simplex Tk+ i. This completes the iteration step from k !o k + 1. So we get after O(d3n) time either a decision or a simplex Td+ ~. In the last case, the simplex has full dimension, hence S :~ 0. []
4. Testing a digital function curve for being a circular arc Let us be given a digital function curve D of size n. We want to decide whether D is the digi!alization of an arc A of a circle C. Obviously A mu~t be part of the upper or lower half of C. Withoui loss of generality we assume that A is in the lower half; for the upper half we can proceed very similarly. (Replace y by - y ) . A circle C has exactly four points the tangents through which have slope + 1 or - 1 . The four disjoint arcs connecting these points are called the quarters of C. Then, in general, A lies " m a i n l y " in the southern quarter, but its ends can paSs in the western and eastern quarter. Further it i s possible that A lies only in the western or eastern quarter. Since D is assumed to be a digital function curve, Lemma 2 yields that all inner pixels of D must satisfy (V) with respect to some circle C , whereas each of the two endpixels satisfies (V) or (H). Conversely, if all pixels of D fulfill these digiialization conditions, the D is a digital circular arc - this follows trivially from the definition of dig. The final lemma excludes some minor itechnical difficulty.
546
P. Damaschke/ Pattern Recognition Letters 16 (1995) 543-548
L e m m a 3. There exists a small constant r o > 0 with the following property: I f C is a circle with radius larger than ro, and A is an arc in the lower half o f C such that D = dig(A) is a digital function curve then the minimum distance o f D to the horizontal line 1 through the center o f C is larger than 7. This is also obvious. Now we have gathered all things which are necessary to prove: Theorem 2. One can decide in O(n) time whether a given digital function curve D with n pixels is a digital circular arc. Proof. In order to reduce the problem to halfspace intersection we use a parametrization of circles which is linear in the parameters. Starting with the usual parametrization (X --S)
( y - t) 2 = r 2
2 "~
(1)
(with s, t, r real numbers) we get x 2 + y 2 + 2 a x + 2by + c -- 0
(2)
where a = - s , b = - t , and c = s z + t 2 - r 2 > 0 we obtain the additional condition
r 2.
a 2 q- b 2 > c
Since (3)
for our parameters a, b, c. The explicit formula of the lower half of the circle is y = -b
-
~/b 2
--X 2
-
-
(4)
2ax - c.
(Clearly the square root gets the negative sign.) Assume D is a digital circular arc in the lower half of some circle. Due to Lemmas 1 and 2, all pixels of D, possibly except the extremal pixels, satisfy q
-- 1
7 <-b-~b2-p2-2ap
-c
~
(5)
for suitable parameters a, b, c. The leftmost and rightmost pixels satisfy analogous inequalities for at least one of the two digitalization conditions. This leads to four case distinctions. In the following we consider the case that all pixels satisfy (V), and hence (5); the other cases are briefly settled later. So input D is accepted if and only if there exist parameters a, b, c satisfying (5) for all ( p , q) ~ D, and additionally (3).
Next suppose r > r 0. Then Lemma 3 implies 1
q < - b- ~
(6)
for all ( p , q) ~ D . (Note that the line y = - b is the horizontal line through the center of the circle described above.) The left inequality of (5) gives --
~b2-p2-2ap
c <-b
_
q + 7 .l
(7)
Since the square root itself is non-negative we can square this inequality, thus obtaining _p2
_
2ap - c < q2 + ~1 + 2bq - b - q
(8)
which is a linear constraint in a, b, c. The right inequality of (5) can be written as: ~ b Z - p 2 - 2ap
__
c >l - b - q
21
(9)
Due to (6), the right side is positive, and we can square (9): - p 2 - 2ap - c >~qe + ~1 + 2bq + b + q
(10)
This is again a linear constraint in a, b, c. Under the assumption r > r 0, the above implications can be reversed; particularly note that b 2 - p 2 - - 2 a p - - c > 0. Hence (5), (3) is equivalent to the conjunction of (8), (10), (6), (3). Hence we accept D if and only if it comes from a circle with radius r ~< r0, or if some parameter triple satisfies (8), (10), (6) for all pixels, and additionally (3). The former case can be trivially tested in constant time, since there are only finitely many questionable patterns (up to translation). In the latter case we will show that the nonlinear constraint (3) is redundant. Hence we have only to test whether the halfspaces defined by the linear constraints (8), (10), (6) have a nonempty intersection. This can be done in O(n) time by Theorem 1. Assume the contrary of (3), namely a 2 + b 2 ~< c for some point (a, b, c) in the intersection polytope. Then we obtain from (10) for each pixel of D: pZ + q Z + 2 a p + 2 b q + b + q + c + a2 + b 2
+ p 2 q_ q2 + 2ap + 2bq + b + q + ~1 <~O,
(a+p)Z +(b+q)2
(b+q)Z+(b+q)+z (b
~.- q -t- 1 ) 2
b+q+7
~l <~0,
1
=0.
~ 0,
+ b + q + z < O1 , 1
<~0,
P. Damaschke/ Pattern Recognition Letters 16 (1995) 543-548
This contradicts (6). Hence (3) is indeed redundant, and we have nothing more to test for our decision. It remains to consider the three cases where the leftmost or rightmost pixel fulfills only (H). Then we get similar constraints for them as above, only the two coordinates change their roles. Particularly note that the constraint analogous to (6) is also satisfied: If an endpixel of D belongs to the southern quarter then it fulfills (V), due to L e m m a 1. Hence, a pixel satisfying only (H) must belong to the western or eastern quarter, so its distance to the vertical diame1 ter of C is at least ~. [] Note that the algorithm of Theorem 2 does not only solve the decision problem, it also yields a constant number of possible parameter polytopes (implicitely given as constraint sets) for the suitable circles. Let us be given an arbitrary but not self-crossing digital curve D. Under the assumption that D is a digital circular arc, there must be a partition of D into at most four digital function curves (with x or y as the independent variable). This follows by Lemma 1 from the partition of the circle into quarters. It is easy to determine the maximal digital function curves in D in linear time. (Note that any two neighbored subcurves of this kind can overlap on a straight line with slope + 1 or - 1 . ) Now, by L e m m a 2 we can assign to each pixel, up to a constant number of exceptions, the condition (V) or (H) which must be necessarily fulfilled. Altogether we have to solve only a constant number of halfspace intersection problems. If the given curve was not a digital circular arc then either the partition of D into digital function curves fails, or we do not get a nonempty parameter polytope. If a given unordered set of n pixels shall be tested for being a digital circular arc, we first have to arrange it to a digital curve. Because of 8-connectivity all abscissa and ordinates, respectively, lie in an interval of size not exceeding n. This can be checked by minimum and maximum computations; if we get a larger interval then the input can be promptly rejected. Then sort the pixels with respect to the coordinates which can be done in O(n) time (instead of O(n log n)), since we have at most n possible values. After that we can easily reconstruct the curve in O(n) time.
547
The details of these preprocessings are straightforward, so we omit them here. Altogether this shows:
Theorem 3. One can decide in O(n) time whether given set of n pixels is a digital circular are.
a
5. Generalizations and further research We have reduced the recognition of digital circular arcs to linear programming. The parameter constraints can be computed for each pixel independently. But the curve passing the pixel can be flat or steep which yields different constraints. Therefore we had to divide the digital curve previously into subcurves related to the quarters of the Circle, in order to avoid an exponential number of cases. Only for this preprocessing the connectivity was important. It arises the question: Can we recognize arbitrary subsets of digital circles in linear time ? Our basic idea works for any fixed finite number of parameters. Hence we can in principle recognize elliptical arcs by the same method. The computations are similar as in Theorem 2 - it is left to the reader to verify that we get linear constraints. But for ellipses with arbitrarily large eccentricity we have the additional problem that an analogon of Lemma 3 does not hold. This may cause expensive Case distinctions for the pixels which are located closely to the line separating the upper and lower half. The digitalization of a complete but very thin ellipse can even be a single digital straight line segment. So the question Can we recognize arbitrary digital elliptical arcs in linear time? remains open. Nevertheless we get linear time if the eccentricity is bounded by a constant; r 0 must be replaced by the minor half axis. From an algorithmic point of view, two further questions are natural: Can our method be parallelized? and: Can we give an efficient dynamic rersion of our method? The latter means: If the input is slightly modified, can we update the result faster than by a completely new computation? Th~s is also interesting for coping with noise. Finally we ask for other r e l e v a n t linearly parametrizable families of curves for which our idea is appropriate.
548
P. Damaschke / Pattern Recognition Letters 16 (1995) 543-548
References Anderson, T.A. and C.E. Kim (1985). Representation of digital line segments and their preimages. Computer Vision, Graphics, and Image Processing 30, 279-288. Creutzburg, E., R. Klette and A. Hiibler (1982). On-line-Erkennung digitaler Geradensegmente in linearer Zeit. Geobild 82, Jena 1982, 48-65. Dyer, M.E. (1984). Linear time algorithms for two and three-variable linear programs. SIAMJ. Comput. 13, 31-45. Kovalesky, V.A. (1990). New definition and fast recognition of digital straight segments and arcs. lOth Internat. Conf. on Pattern Recognition, Atlantic City, NJ.
Landau, U.M. (1987). Estimation of a circular arc center and its radius, Computer Vision, Graphics, and Image Processing 38, 317-326. Megiddo, N. (1983). Linear time algorithm for linear programming in ~3 and related problems. SIAM J. Comput. 12, 759-776. Megiddo, N. (1984). Linear programming in linear time when the dimension is fixed. J. ACM 31, 114-127. Sauer, P. (1993). On the recognition of digital circles in linear time. Computational Geometry 2, 287-302. Thomas, S.M. and Y.T. Chan (1989). A simple approach for the estimation of circular arc center and its radius. Computer Vision, Graphics, and Image Processing 45, 362-370.