<<

International Journal of Computer Vision 54(1/2/3), 159–182, 2003 c 2003 Kluwer Academic Publishers. Manufactured in The Netherlands.

Euler Spiral for Shape Completion

BENJAMIN B. KIMIA, ILANA FRANKEL AND ANA-MARIA POPESCU Division of Engineering, Brown University, Providence, R1 02912, USA

Received May 25, 2001; Revised September 20, 2002; Accepted February 3, 2003

Abstract. In this paper we address the curve completion problem, e.g., the geometric continuation of boundaries of objects which are temporarily interrupted by occlusion. Also known as the gap completion or shape completion problem, this problem is a significant element of perceptual grouping of edge elements and has been approached by using cubic splines or biarcs which minimize total curvature squared (elastica), as motivated by a physical analogy. Our approach is motivated by railroad design methods of the early 1900’s which connect two rail segments by “transition curves”, and by the work of Knuth on mathematical typography. We propose that in using an energy minimizing solution completion curves should not penalize curvature as in elastica but curvature variation. The minimization of total curvature variation leads to an Euler Spiral solution, a curve whose curvature varies linearly with arclength. We reduce the construction of this curve from a pair of points and tangents at these points to solving a nonlinear system of equations involving Fresnel Integrals, whose solution relies on optimization from a suitable initial condition constrained to satisfy given boundary conditions. Since the choice of an appropriate initial curve is critical in this optimization, we analytically derive an optimal solution in the class of biarc curves, which is then used as the initial curve. The resulting yield intuitive across gaps and occlusions, and are extensible, in contrast to the scale-invariant version of elastica. In addition, Euler Spiral segments can be used in other applications of curve completions, e.g., modeling boundary segments between curvature extrema or modeling skeletal branch geometry.

1. Introduction disambiguate the optimal grouping (Parent and Zucker, 1989; Sha’ashua and Ullman, 1988). The human visual system is constantly confronted with The process of completing contours beyond occlu- complex scenes where objects are partially occluded by sions or across gaps, alternatively referred to as the others, Fig. 1. Yet, it can effortlessly identify fragments curve completion, gap completion,orshape comple- which belong together and construct a complete ob- tion problem, is under-constrained: in completing a ject representation from them. Similar phenomena have missing contour, e.g., the kangaroo’s back across the been observed in completing the trajectory of a moving occlusion in Fig. 1, there exist numerous curves that object which is temporarily occluded. Gestalt psychol- meet the “boundary conditions” of passing through ogists understood the significance of completing con- specified endpoints and tangents. The selection of the tours which are interrupted by occlusions and explored optimal completion curve, therefore, has typically re- it, e.g., in the special case where the occluder blends lied on assumptions regarding on what constitutes the with the background, thus generating illusory or sub- most “likely” curve or the most “pleasing” or the jective contours, Fig. 1. In computer vision, where re- “smoothest” curve (Nitzberg et al., 1993). sults from low-level edge operators need to be grouped The explicit recovery of a completion curve is use- into complete object boundaries, e.g., for recognition, ful in a variety of visual tasks, such as the task a number of approaches have been developed that take of disambiguating edge maps in perceptual group- advantage of the properties of the completion contour to ing, the partitioning of visual form for part-based 160 Kimia, Frankel and Popescu

Figure 1. (a) Branches of a tree occlude each other, but each branch maintains its “identity” across such occlusions. (b) The same idea is illustrated for an occluded kangaroo where the continuity between the two separated segments is maintained. In addition, note that in mentally removing a part, e.g., the front paw, we are able to continue the main body outline. (c) Illusory contours arise from an occluder that blends with the background. object representation and recognition, and for filling- phenomenon and in inpainting, the presence of recon- in tasks in the reconstruction of occluded areas structed contours allows for proper filling-in of the in- in figure-ground segregation. First, Fig. 2(a) depicts a ternal regions, thus avoiding diffusion in the missing series of edges which sample an object boundary, but contour areas, Fig. 2(c). with missing gaps and embedded in a set of spurious edges. In perceptual grouping tasks, spurious edges Curve Completion in Other Domains: The problem of must be identified and removed, while gaps must be selecting an optimal visual interpolation across miss- filled in. Williams and Thornber (1999) describe and ing boundaries is not unique to vision. In design, compare a class of such approaches where an affin- mechanical engineers have used “French Curves”, ity measure is first computed for each pair of edges to a template consisting of a large number of smooth describe the likelihood that they belong to the same curves, to complete the partially specified surface boundary. This is then followed by an optimization of ships, aircraft fuselage, etc. (Farin, 1996), Fig. 3. over groupings of a larger set of edges, or curve hy- Similarly, in computerized typography, where fonts potheses, to determine the saliency of each edge el- need to be specified in a formal scalable language, ement. The properties of the completion curve, such partially specified letters and symbols need to be as total curvature, have been used as the affinity mea- smoothly interpolated (Knuth, 1979). In compress- sure, some of which require an explicit recovery of the ing shapes for example, retaining a sampling of completion curve. Second, the completion curve has curvature extrema with their tangent is an efficient been used as the “break curve” in partitioning shapes, representation of the shape if appropriate contour where the properties of the completion curve are used completion algorithms are available. In civil engi- to disambiguate conflicting part hypotheses, Fig. 2(b) neering, this geometric interpolation problem arises (Dhandapani and Kimia, 2002; Siddiqi and Kimia, in highway turn-out design, railroad construction, 1995). Third, in visual tasks emulating the filling-in e.g., between two specified tunnel entrances, and the

Figure 2. The Euler spiral completion curve is particularly useful in (a) disambiguating perceptual grouping of edge maps, (b) resolving conflicts among break curves in partitioning tasks, and (c) in augmenting the current inpainting techniques to avoid diffusion across missing boundaries. Euler Spiral for Shape Completion 161

and has been the topic of numerous formalizations, es- pecially in the context of subjective contours (Kanizsa, 1979). Ullman (1976) suggests that the interpolated curve C, which should depend only on the relative ge- ometry of the point-tangent pairs, must satisfy the fol- lowing axioms: Figure 3. (a) The use of French Curves in the field of mechanical design employs was common place for drawing smooth curves of C a range of curvatures (Weisstein, 1998). (b) We suggest here that 1. is invariant to rotations and translations (isotropy). segments of the Euler Spiral can serve this purpose well. 2. C is at least differentiable once (smoothness). 3. C minimizes total curvature—using the thin beam analogy (minimum total curvature). resulting curve is known as a transition or ease- C ment curve (Higgins, 1921; Kurtz, 1945; Talbot, 4. is extensible (originally referred to as locality); as 1927). More modern applications include the design defined below. of roller-coasters and bike tracks, Fig. 4. Finally in C , , our own quotidian lives, we confront various forms Definition. An interpolation between A0(x0 y0 θ 2 , ,θ , of this problem, e.g., in parking and other driving 0) and A2(x2 y2 2)isextensible if for any A1(x1 y1,θ1)onC the interpolation between A0 and A1 and scenarios. C In this paper, we assume that a pair of point- that between A1 and A2 both coincide with . tangent pairs are under consideration, e.g., a can- didate pair of T-junctions or curve endpoints. The While Ullman hints at the doubly cantilever-ed beam properties of the optimal completion curve such as and the related cubic approximation as the loci of smoothness, length, etc. (Sha’ashua and Ullman, minimum curvature (Ahlberg et al., 1967; Sokolnikoff, 1988) as well as its spatial interaction with exist- 1956), he proposes a completion curve consisting of ing curves and completion contours will be crucial two circular arcs, one tangent at one point edge and the in identifying the optimal grouping of point-tangent other tangent to the other edge, and both tangent to each pairs. Thus, the problem we address can be formu- other. Since there exist multiple biarc solutions, the lated as: minimum total curvature property is used to select the optimal biarc. He then suggests a three-layer network Problem Statement: Given a pair of points A0(x0, y0) with local connections to achieve this. As we shall see, and A2(x2, y2), with associated unit tangent vectors,   the computation of a biarc solution is also integral to T0(cos θ0, sin θ0) and T2(cos θ2, sin θ2), find the most “pleasing” curve which passes through both points the approach here, but one which minimizes curvature at their respective tangents.1 difference not total curvature. Rutkowski (1979) analyzes the minimum total cur- Despite the appeal of our visual intuition for the ex- vature biarc construction of Ullman, describes a numer- istence of a solution, this problem is under-specified ical method for computing it, and compares the results

Figure 4. (a) In this Vekoma roller coaster, Joker’s Revenge, the train runs backward; amusement-seekers leave the station with no view of where they are headed. In fact, they are about to loop a teardrop-shaped loop which is composed of a circular upper arc joined to lower Euler Spiral arcs (Baldwin, 1996). (b) The Velodrome at Stone Mountain Park, the Cycling Venue for the 1996 Olympic Games, is the first in a new generation of high-performance bike tracks these tracks are partially designed based on the Euler’s spiral (http://www.kd3bj.ampr.org/track/). 162 Kimia, Frankel and Popescu to cubic completions. He concludes that “it Knuth concludes that axioms 3, 4, 5, and 6 cannot be si- appears that, in many cases, the cubic polynomial com- multaneously satisfied, and remarks that although “the pletions have a more pleasing appearance than the two locality property is the most suspicious one,” he does circle completions.” Brady and Grimson (1980) state not want to give it up; hence he concludes that “the that Ullman’s biarc completion curve is, in fact, not extensibility property has to go.” The remaining ax- extensible. They instead follow Knuth’s approach (de- ioms suggest a cubic for any in- scribed below) of giving up on the extensibility axiom terval (zk , zk+1) with known tangent-directions (com- and support the use of cubic splines. Specifically, they puted from a local neighborhood based on the above propose to search in the space of cubic polynomial for conclusions) at these points—which is precisely the the completion curve which minimizes a curve-related curve completion problem. Note, however, that the cu- energy. bic spline interpolation does not satisfy axiom 6 since Consider the approach to the construction of a com- such an interpolation can only approximate a circle. pletion curve in typography where the shape of symbols Observe that due to the invariance axiom 1, we can is only partially specified by a collection of points, and generally state the final interpolation between any two needs to be completed in the most pleasing manner point-tangent pairs as the cubic spline interpolation (Knuth, 1979). The fundamental problem underlying between (0, 0,θ0) and (1, 0,θ2) which is, in complex the mathematically rigorous design of these shapes— number notation: irrespective of style or size—can be posed as: “given a θ = 2 − 3 + i 0 − 2 sequence of points in the plane, what is the most pleas- z(s) 3s 2s r0e s(1 s) iθ2 2 ing curve that connects them?” (Knuth, 1979). This − r2e − s (1 − s), (1) problem, therefore, is similar (and later shown to be equivalent) to our geometric interpolation in that it re- where    quires the selection of an optimal curve which adheres    θ  to our traditional sense of aesthetic, axiomatizes the = 1,  4 sin 2   , r0 max  θ +θ θ +θ  beauty of letters, and captures how “pleasing” the re- 2  1 + cos 0 2 sin 0 2    2 2  sulting interpolation is.3 In light of this, and to allow    θ  = 1,  4 sin 0   . for a certain degree of freedom in the interpolation, r2 max  θ +θ θ +θ  2  + 0 2 0 2  Knuth defines the most “pleasing” curve through a set 1 cos 2 sin 2 of points z ,...,z , as the closed curve C which sat- 1 n The results of this interpolation, with and without isfies a set of axioms, somewhat similar to Ullman’s the maximum operation specifying r and r , are axioms. Specifically, they require 0 2 shown in Fig. 5. The application of this to type design 1. C is invariant to translation, rotation, and scaling; gave rise to Knuth’s METAFONT system which 2. C is invariant to cyclic permutation or reversal of has been largely successful in the modern LaTeX 4 order of traversal (symmetry); computerized typesetting. 3. Adding a new point already on C to the list does not change this solution (extensibility); Elastica: Horn argues that since the total energy stored 4. C is locally constructed; i.e., each segment of the in a thin beam (Horn, 1983) is proportional to the inte- gral of the square of curvature, the curve which mini- most pleasing curve between zk and zk+1 depends  mizes κ2dSwhere κ is curvature and ds is arc-length, only on (zk−1, zk , zk+1, and zk+2)(locality); 5. C has no sharp corners (smoothness); and, and which satisfies the given point-tangent bound- 6. If C interpolates four consecutive points lying on a ary condition, represents the “smoothest” completion circle, then C is a circle (roundedness).

Knuth then shows that these axioms in conjunction im- ply that: (i) the direction of the tangent to the most pleasing curve at zk depends only on (zk−1, zk , zk+1); (ii) this tangent must be tangent to the circle passing , , Figure 5. (a) The result of the interpolation without the maximum through (zk−1 zk zk+1); and, (iii) this tangent depends operation specifying r and r for a range of tangents. (b) The result , 0 2 only on zk+1 zk , and the tangent at zk−1. However, of the interpolation with the maximum operation specifying r0 and the latter implication violates the previous ones. Thus, r2, taken from Knuth (1979). Euler Spiral for Shape Completion 163 shape. He derives differential equations for this curve completed consistently. Even when β = 0, the en- both in terms of elliptic integrals and Cartesian coordi- ergy of the curve, and thus its “salience”, varies with nates. It is then shown that this completion curve is ex- scale (distance between points) relative to competing tensible. In relation to minimum total curvature biarcs hypotheses. This has prompted an approach wherein of Ullman (1976), he also examines the optimal multi- the elastica energy is scaled by total length (Sharon arc approximations, and observes that in this multi-arc et al., 2000; Weiss, 1988; Onn and Bruckstein, 1990). solution arcs tend to be of equal length while curvature But this implies that the computation of the completion increases more or less linearly along the curve. Interest- curve becomes global, and thus is not extensible:given ingly, this property implicitly points to the Euler Spiral any point on a completion curve C, the two comple- presented here; however, he finds that the latter curve tion sub-problems do not necessarily coincide with the has higher total squared curvature than the multi-arc so- same C. lution with a sufficient number of segments. Thus, the Sharon et al. (2000) address the computational as- Euler Spiral is not seen to be an appropriate candidate pects of finding the optimal completion curve and pro- for shape completion.5 pose analytic expressions for approximating it. Based More recently, Mumford (1994) notes the historical on the assumption that the deviation angle of the tan- role of elastica in obtaining the optimal curve through gents from the line connecting the endpoints is small, two specified points with specified orientations (Euler, they derive cubic Hermite spline approximations. A 1744; Love, 1927; Bryant and Griffiths, 1986), i.e., the second expression in terms of these deviation angles curve which minimizes is then shown to be accurate even when the above as-  sumption is not valid. The result is a numerical method 2 (ακ + β) ds, (2) which is accurate and relatively fast. We now motivate a new approach by first consid- α, β where are constants. Mumford interprets these ering the third difficulty, namely, that elastica, least elastica from the Bayesian view as “the mode of the energy curves minimizing κ2, do not lead to circular probability distribution underlying a certain stochas- interpolations (Sharon et al., 2000). The intuition that tic process restricted to curves with prescribed bound- two (co-circular (Parent and Zucker, 1989)) edge ele- ary behavior” (Mumford, 1994), Fig. 6. Similarly, ments with equal angles to the line connecting them Williams and Jacobs (1995, 1997) model the comple- should be completed via a circular arc regardless of tion shapes as the most likely one in a family of curves, curvature thus argues for minimizing not total curva- and like Mumford, model this by a random walk in ture but total change in curvature. We propose that the the space of positions and orientations, leading to a energy functional which properly captures the elusive stochastic completion field. An extensive model has nature of “the most pleasing curve” penalizes change in been developed on this idea for disambiguation of edge curvature, but not necessarily curvature proper. Thus, maps and perceptual grouping (Williams and Jacobs, we seek the curve specified with the curvature function 1995, 1997; Williams and Thornber, 1998). κ(s), s ∈ [0, L] and with arc-length L which minimizes The major shortcomings of the elastica are that (i)  they are not scale-invariant, (ii) they are computation- L ally expensive to derive, and (iii) they do not lead to cir- κ = κ2 , E[ ] s ds (3) cular completion curves when the point-tangent pairs 0 are, in fact, co-circular (i.e., both lie on the same cir- cle). Scale-invariance is necessary since these curves subject to the boundary conditions (x0, y0,θ0), are used to model completion say gap completion, in (x2, y2,θ2). Using calculus of variation the correspond- a world where the distance from the observer to the ing Euler-Lagrange equation is κss = 0, for which the imaged object varies constantly, yet the gaps must be general solution is the linear curvature curve κ(s) = γ s + κ0, with two arbitrary parameters κ0 and γ .How- ever, we have yet to satisfy the boundary constraints in this optimization. Observe that in the case of elastica the unconstrained Euler-Lagrange equation for κ2 ds leads to κ = 0, which generally cannot satisfy endpoint constraints.6 In our case, these endpoint constraints can Figure 6. Examples of elastica from Mumford (1994). be satisfied for the general class of curves described by 164 Kimia, Frankel and Popescu

κss = 0—that is, the class of curves described by linear the intensity of the illumination of a diffraction pattern curvature profiles, otherwise known, in the mathemat- as the sum of squares of each such integral (Euler’s, ical literature, as the Euler Spiral, the Cornu Spiral or 1918), C2(s) + S2(s), where C and S are the Fresnel the clothoids, and, in civil engineering, as the Railroad Integral, Spiral or the Transition Curve. The paper is organized as follows. In Section 2 we (C(s), S(s)) will examine equations for the construction of the Euler     spiral and identify parameters needed to specify it in a s π s π 2 2 form that is suitable for this problem. In Section 3, we := cos ξ dξ, sin ξ dξ , 2 2 will address the question of finding parameters such 0 0 that the Euler Spiral segment meets the end-points with F(s) = C(s) + iS(s), (5) specified tangents, thus solving the curve completion problem. We reduce this to solving a system of non- linear equations in two unknowns which we then solve which are typically either calculated and readily avail- by numerical optimization from a closeby initial curve able from tables originally created by Fresnel, ex- estimate. We rely on a biarc initial estimate which panded in terms of the spherical Bessel Functions minimizes total squared curvature change, as opposed (Abramowitz and Stegun, 1972; Leonard, 1988; Press to Ullman’s biarc which minimizes total curvature et al., 1993; Spanier and Oldham, 1987), or com- squared. Towards this end, Section 4 examines the puted by integrating the Taylor expansion term by space of biarcs which meet the end-points at specified term (Abramowitz and Stegun, 1972; Press et al., tangents and analytically derives the optimal biarc 1993): in the sense of the minimal curvature change. This biarc, with a piecewise constant curvature profile, is   ∞ − n π 2n in fact geometrically close to the Euler spiral which ( 1) + C(s) = 2 s4n 1, has a linear curvature profile and is used as the initial + n=0 (2n)!(4n 1) estimate to derive the optimization. Section 5 presents   examples of the Euler spiral interpolation for syn- ∞ π 2n+1 (−1)n thetic and realistic solutions, which are intuitive and = 2 4n+3. S(s) + + s extensible. n=0 (2n 1)!(4n 3)

Then, in 1874, Cornu plotted the Euler’s Spiral 2. Euler’s Spiral accurately (Cornu, 1874); the curve thus acquired another name: Cornu’s Spiral. And Cesaro, upon study- The Euler Spiral was considered by Euler in connec- ing the curve and establishing a number of its prop- tion to his investigation of a freely coiled up elastic erties, dubbed it the “clothoid” from the Greek word spring held taut horizontally by a weight at its ex- meaning “to twist by spinning” (Cesaro, 1886). Note tremity (Euler, 1744). In its natural, relaxed position, that we henceforth refer to this curve as the Euler’s the spring satisfies κ = 1 s, where a is a constant, a2 Spiral in connection with Euler’s investigations of κ s is arc-length, and is curvature. By a simple inte- it. θ gration of curvature and then the tangent angle (s) It is immediately apparent that the computation and C = , we obtain the equations for the curve (s) (x(s) visualization of the Euler Spiral relies on the Fres- y(s)), nel integrals. The following proposition states the gen- eral form of the Euler spiral with a specified boundary  2 s s iξ2 condition. θ = , C = 2a2 ξ. (s) 2 (s) e d (4) 2a 0 Proposition 1. The general form of the Euler Spiral This set of integrals came to be known as the Fresnel’s C(s), which passes through C0(x0, y0) at tangent angle (1788–1827) integrals in connection with his model of θ0, with curvature κ0, and a rate of change of curvature Euler Spiral for Shape Completion 165

γ, can be written as  iθ0 C0 + e s γ = 0,κ0 = 0  θ  i 0 C + e κ + − κ γ = ,κ =  0 κ (sin( 0s) i(1 cos( 0s)) 0 0 0 0           κ2  π i θ − 0 κ + γ κ κ + γ κ C + 0 2γ × γ √0 s − √ 0 + √0 s − √ 0 ,γ=  0 |γ | e sign( ) C C i S S 0  π|γ | π|γ | π|γ | π|γ | (6) and θ(s) = 1 γ s2 + κ s + θ in all cases. 2 0 0 γ< For √ 0, the computations are similar, except that −γ is used instead, leading to the term in Proof: The Euler spiral C(s) is obtained by integrat- Eq. (6). ing κ(s) = γ s + κ0 using Eq. (4), giving , ,θ κ  Thus, given (x0 y0 0), two free parameters 0 and  1 γ must be obtained in order to define the spiral. An ad- θ(s) = γ s2 + κ s + θ ,  0  0  ditional parameter L is needed to delineate a segment 2 s (7) 1 γξ2+κ ξ+θ  i 0 0 of the spiral by its total length; so six parameters in C(s) = C0 + e 2 dξ. 0 total, (x0, y0,θ0) and (κ0,γ,L), are required in order to define an Euler Spiral segment, the canonical geo- First, if γ = 0 and κ0 = 0, it is straightforward to metrical element which we later use to solve the curve derive the first expression in Eq. (6), which gives a completion problem. The spirals in Fig. 7 illustrate the κ γ straight line. Second, if γ = 0 and κ0 = 0, then effect of varying 0 and for fixed L.  s 3. Euler’s Spiral for Curve Completion iθ0 iκ0ξ C(s) = C0 + e e dξ 0 iθ We now examine how the Euler Spiral segment e 0 κ = C + − i 0s , can be used for the geometric interpolation of two 0 i κ (1 e ) (8) 0 point-tangent pairs for curve completion. leading to the second expression in Eq. (6), which gives Proposition 2. Consider the Euler Spiral C(s) a circle. Finally, when γ = 0, consider first γ>0. We satisfying end-point conditions C0(x0, y0) with complete the square term in the exponent in Eq. (7) and γ κ π ξ + 2 0 = τ using the substitution 2 γ 2 2 , obtain

 √   s κ 2 κ2 γ ξ+ 2 0 +θ − 0 i 2 γ 2 0 2γ C(s) = C0 + e dξ, (9) 0 κ +γ    ( √0 s) κ2 π πγ 2 i θ − 0 i πτ = C + e 0 2γ e 2 dτ. (10) 0 κ √ 0 2 πγ which gives,   π κ2 κ + γ i θ − 0 0 s C = C + 0 2γ √ (s) 0 γ e C πγ

κ κ + γ s − √ 0 + 0√ C πγ i S πγ κ Figure 7. An Euler spiral segment starting at the origin and tangent − √ 0 . to the x-axis of a given length is shown by varying initial curvature S πγ (11) κ0 and rate of change of curvature γ of the Euler Spiral. 166 Kimia, Frankel and Popescu

 κ tangent T 0(cos θ0, sin θ0), and C2(x2, y2) with tangent and 2.  θ , θ , T 2(cos 2 sin 2) which is identified by six parameters  , ,θ ,κ ,γ, C − C = iψ , (x0 y0 0 0 L). Let 2 0 L0e . Then κ2 = γ L + κ0, , , if the point-tangent pairs are cocircular i.e. if 1 (14) θ2+θ0 2 θ0−θ2 θ = γ 2 + κ + θ , ψ = , then γ = 0,κ0 = κ2 = sin( ) and 2 L 0 L 0 2 L0 2 2 L0(θ0+θ2) θ2+θ0 = θ +θ , ψ = , L 0 2 . Otherwise if 2 then 4 sin( 2 ) 1 and simplifying θ2 = (κ2 − κ0)L + κ0 L + θ0 =  κ +κ 2 2 2 2 0  κ − κ L + θ0, results in Eq. (12) for L. In other words,  γ = 2 0 , 2 2(θ − θ ) the length of a spiral segment is the change in ori- 2 0 (12)  entation (θ2 − θ0) divided by its average curvature  2(θ2 − θ0) κ +κ  L = , ( 2 0 ). In addition, note that if κ = κ we derive κ + κ 2 0 2 2 0 expressions where κ0 and κ2 satisfy   π √  θ − θ   2 0  C − C = 2π , 2 0 |γ | κ2 − κ2      2 0 θ κ2−θ κ2 √  θ − θ  i 0 2 2 0  2 0  κ2−κ2 κ2 θ − θ = 2π  e 2 0 θ − 0 = θ − κ2 2 0 κ2 − κ2 0 0 0 2 0 2γ κ2 − κ2     2 0 2 2   2 2 κ − κ 2 θ − θ θ0κ − θ2κ × sign 2 0 C  2 0 κ = 2 0 , θ − θ π κ2 − κ2  2 κ2 − κ2 2 0 2 0 2 0        θ − θ  κ + γ L 2  θ − θ  2  2 0  √0 = κ  2 0 , − C κ 2   (15) π κ2 − κ2  0 π|γ | π κ2 − κ2 2 0 2 0      θ − θ  + 2  2 0 κ i S  2 2  2 which are needed to simplify Eq. (13) in terms of two π κ − κ θ +θ 2 0 κ ,κ ψ = 0 2   unknowns ( 0 2). If , the two point-tangent   2 θ +θ κ = κ = 2 0 2 = 2  θ − θ  pairs are cocircular. with 0 2 sin , L  2 0  θ +θ L0 2 − S κ L0( 0 2  2 2  0 θ +θ . Obviously, a circular arc is an Euler Spiral π κ − κ 4 sin( 0 2 ) 2 0 segment2 with γ = 0, so that it solves the geometric θ +θ interpolation problem. On the other hand, if ψ = 0 2 , Proof: Observe that the input is specified through 2 then κ0 = κ2, γ = 0, and we have six known variables (x0, y0,θ0; x2, y2,θ2). The descrip- tion of the Euler Spiral also requires six parameters,   κ2 (x , y ,θ ; κ ,γ,L), which explicitly include parame- π 0 κ + γ 0 0 0 0 i θ0− γ 0 L  C2 = C0 + e 2 sign(γ ) C √ ters defining C0 and T 0, namely, (x0, y0,θ0). Thus, we |γ | π|γ | κ ,γ, need to compute ( 0 L) such that the spiral segment κ κ + γ L  − C √ 0 + i S √0 ends at C2 with tangent T 2. This gives two constraints, π|γ | π|γ | κ = , 0 C(L) C2 − S √ (13) π|γ | θ(L) = θ2,     θ κ2−θ κ2 √  θ − θ  i 0 2 2 0  2 0  κ2−κ2 = C + 2π e 2 0 where C and θ are specified in Proposition 1. This gives 0 κ2 − κ2  2 0   three equations for the three unknowns (κ0,γ,L), in   , ,θ , ,θ κ2 − κ2 2  θ − θ  terms of the known parameters (x0 y0 0; x2 y2 2). × sign 2 0 C  2 0 κ θ θ − θ π κ2 − κ2  2 Note that the equation for 2 can be used effectively to 2 0 2 0 reduce the parameter search by one.7 Consider κ and     0  θ − θ  κ , the curvatures at C and C , respectively, as a set 2  2 0  2 0 2 − C  κ0 κ γ, κ π κ2 − κ2 of free parameter, i.e., 2 rewrite L in terms of 0 2 0 Euler Spiral for Shape Completion 167

Figure 8. Given a pair of points-tangent pairs specified by, (x0, y0,θ0; x2, y2,θ2), multiple solutions can be obtained as the Euler Spiral can reach the same angle infinitely many times due to its winding nature, as illustrated above. We seek the shortest solution which do not wind more than 2π.

    θ −θ  θ − θ  2 0. To show scale invariance, we have to show that 2  2 0  + i S κ parameters pertaining to a scaled Euler Spiral satisfy π κ2 − κ2  2 2 0   Eq. (13) for scaled parameters. A scaling by a factor   α C − C 2  θ − θ  of scales 2 0 by this factor, but does not affect − S  2 0 κ , (16) θ − θ π κ2 − κ2  0 2 0. A scaling of the Euler Spiral, on the other hand, 2 0 1 scales its curvature by α and its rate of change of cur- κ 1 κ = 0 vature by α2 . Thus, it must be shown that ˜0 α , a system of two equations in two unknowns (κ0,κ2). κ κ = 2 γ = 1 γ α C − C ˜2 α , and ˜ α2 satisfy Eq. (13) for ( 2 0), i.e., that the right hand side is scaled by α, which is Since there is no known direct analytic solution for evident by a term by term examination. this nonlinear set of equations, we employ numerical optimization, i.e., a gradient descent approach, start- ing from a suitable initial estimate, such that the ini- Proposition 4. The Euler Spiral interpolation be- tial estimate is evolved until the final Euler spiral so- tween C0(x0, y0,θ0) and C(x2, y2,θ2) is extensible. lution is reached. Due to its spiral nature, the Euler Spiral reaches the same angle infinitely many times, Fig. 8. We are, however, only interested in the shortest Proof: The proof is rather straightforward. Let solution—thus the overall range of θ(s) is restricted C1(x1, y1,θ1) be an arbitrary point on the Eu- to 2π. In consideration of this constraint, the selection ler Spiral interpolation between C0(x0, y0,θ0) and of an appropriate initial estimate (the biarc approxi- C2(x2, y2,θ2), specified by (x0, y0,θ0,κ0,κ2,γ) as de- mation) and the use of explicit constraints in the nu- fined in Proposition 3, where θi is the tangent of the merical optimization become critical, as discussed in Euler spiral at (xi , yi ). Let L1 and κ1 be the length pa- Section 4. We first show that the Euler spiral has the rameter and curvature of the Euler Spiral at C1, respec- required properties of visual interpolation for shape tively. Since C1(x1, y1,θ1) is a point of the interpolation, completion. we have

Proposition 3. The Euler Spiral ES passing through    π κ2 κ + γ , ,θ , ,θ  i θ − 0 0 L1 (x0 y0 0) and (x2 y2 2) satisfies the visual interpo- C = C + 0 2γ γ C √  1 0 e sign( ) lation’s required property of invariance to translation,  |γ | π|γ |  ,  κ κ + γ rotation and scaling. That is the ES interpolations of  0 0 L1  − C √ + i S √ translated, rotated, scaled boundary conditions data  π|γ | π|γ | , , is the translation rotation or scaling of the ES inter-   κ (17) polation of the initial boundary conditions.  − S √ 0  π|γ |   Proof: The proof for translation and rotation is triv-  1 C − C θ = γ L2 + κ L + θ , ial since Eq. (13) contains relative terms 2 0 and 1 2 1 0 1 0 168 Kimia, Frankel and Popescu

where κ1 = κ0 + γ L1. We now seek the interpolation κ κ + γ L − C √ 0 + i S √0 between C1 and C2 as the solution (κ˜0, γ,˜ L˜ )of π|γ | π|γ |    κ π κ˜2 κ + γ ˜ 0  i θ˜ − 0 ˜0 ˜ L − √  C = C + 0 2γ˜ γ C √ S  2 1 e sign( ˜ ) π|γ |  |γ˜ | π|γ˜ |  = C = .  κ˜ κ˜ + γ˜ L˜ 2 LHS (20)  − C √ 0 + i S √0 π|γ˜ | π|γ˜ |  This implies that the Euler spiral interpolation between  κ˜ (18) C C C C  − S √ 0 1 and 2 coincides with that between 0 and 2.A  π|γ | C  ˜ similar result holds for the interpolation between 0  1 and C .  θ = γ˜ L˜ 2 + κ˜ L˜ + θ . 1 2 2 0 1 Consider now Euler Spirals Cn(s), where n is the We need to show that the previous Euler spiral is the iteration number and where each spiral is described solution here, i.e., the Euler spiral with γ˜ = γ , κ˜ = 0 by its initial point-tangent pair (x0, y0,θ0) and, its two κ1 = κ0 + γ L1 and L˜ = L − L1 solves the above κn,κn free parameters ( 0 2 ) as described in Proposition 2. equations. In this case, the right hand side of the second n Note that C (L) does not necessarily meet C2, but its end equation in (18) is n tangent θ (L) = θ2 is correct by construction. Now, we { κ0,κ0 , κ1,κ1 ,..., κn,κn ,...} seek a sequence ( 0 2 ) ( 0 2 ) ( 0 2 ) 1 2 C γ˜ L˜ + κ˜0 L˜ + θ1 where the distance between the second point 2 and the 2 end point of the spiral Cn(L) is decreasing, i.e., where 1 2 C − Cn = γ (L − L1) + κ1(L − L1) + θ1, (19) the sequence 2 (L) 2 converges to zero. Note 2 that E = 0 if and only if the interpolating Euler Spiral which after expanding the first two terms and simpli- is obtained. In Section 4, we analytically obtain a biarc interpolant which gives the initial conditions (κ0,κ0). fying the resulting expression, yields θ2. Similarly, we 0 2 show the correctness of the first equation in (18) by Since the biarc is a close approximation of the Euler simplifying the right hand side Spiral, in practice only a few iterations are necessary for convergence.   π (κ +γ L )2 i 1 γ L2+κ L +θ − 0 1 = C + 2 1 0 1 0 2γ RHS 1 |γ |e 4. Biarc Construction and Interpolation κ + γ L + γ (L − L ) × sign(γ ) C 0 √1 1 π|γ | We now examine a solution of the geometric interpola-

κ + γ L tion between two point-tangent pairs in terms of biarcs. − C 0√ 1 π|γ | The curvature of a biarc is piecewise constant and as such it is an approximation to the linear curvature vari- κ + γ L + γ (L − L ) ations of the Euler Spiral. In fact we shall see that the + i S 0 √1 1 π|γ | biarc which minimizes curvature variation, i.e., cur- vature difference between its arcs while satisfying the κ + γ L − S 0√ 1 boundary conditions is a rather close approximation π|γ | of the Euler Spiral. The analytic formulas we derive   π κ2 κ + γ i θ − 0 0 L here enable it to be used as an initial condition for the = C + e 0 2γ sign(γ ) C √ 1 |γ | π|γ | derivation of the Euler Spiral in a numerical scheme. Specifically, consider that the construction of a biarc κ + γ L κ + γ L − C 0√ 1 + i S √0 requires seven parameters: an initial point-tangent pair π|γ | π|γ | as well as the curvature and lengths of each arc con- κ + γ L strains the parameters of the biarc so that it passes − S 0√ 1 π|γ | through two points with prescribed tangents, consumes   six degrees of freedom, giving rise to a one parameter π κ2 κ + γ i θ − 0 0 L family of biarcs which interpolate two point-tangent = C + e 0 2γ sign(γ ) C √ 0 |γ | π|γ | pairs. We will then analytically derive the biarc with Euler Spiral for Shape Completion 169

rived using the formula for the tangent angle at an ar- bitrary point on the biarc: θ(s) = κ1s + θ0, for 0 ≤ s ≤ L1,

θ(s) = κ2(s − L1) + θ1, for L1 ≤ s ≤ L1 + L2. (23)

Thus, θ1 =2π κ1 L1 + θ0, where =2π denotes equality modulo 2π. Note that as κ1 approaches 0, Eq. (21) in Figure 9. This figure illustrates the biarc interpolation between the the limit is simplified as point-tangent pair (C0(x0, y0),θ0) and (C2(x2, y2),θ2). The point where the two arcs come together is not specified appriori. x(s) = x0 + s cos θ0 y(s) = y + s sin θ , minimum total curvature variation and use it as the ini- 0 0 tial estimate for the Euler spiral. i.e., the equation for a line. Similarly, as κ2 approaches 0, Eq. (22) is rewritten as 4.1. Biarc Construction   = + 1 κ + θ − θ x(s) x0 κ (sin( 1 L1 0) sin 0)  1 Consider the construction of a biarc given an initial   + (s − L ) cos θ point and orientation (x , y ,θ ) and the curvatures and 1 1 0 0 0 for L ≤ s ≤ L + L . lengths corresponding to the two circular arcs from  1 1 2  = − 1 κ + θ − θ which a biarc is composed (κ , L ,κ , L ), Fig. 9. Let y(s) y0 κ (cos( 1 L1 0) cos 0) 1 1 2 2  1 s denote arclength. Assuming κ1 = 0, the first arc is + (s − L1) sin θ1 constructed by means of:  1 This is the complete specification of a biarc using seven  = + κ + θ − θ , ,θ ,κ , ,κ , > x(s) x0 (sin( 1s 0) sin 0) parameters (x0 y0 0 1 L1 2 L2). Note that L1  κ1 0 and L2 > 0 while curvatures κ1 and κ2 can take any  = − 1 κ + θ − θ (21) finite value. y(s) y0 κ (cos( 1s 0) cos 0)  1 for 0 ≤ s ≤ L1, 4.2. A Family of Biarc Interpolants and similarly assuming that κ2 = 0, the second arc using the end point of the first arc, We now identify the biarcs which satisfy the boundary conditions, i.e., pass through a pair of points with  specified tangents. Since there are six constraints and  1  = + κ + θ − θ seven variables, multiple biarcs can possibly satisfy x(s) x0 κ (sin( 1 L1 0) sin 0)  1 these conditions. Thus, we characterize the set of   + 1 κ − + θ − θ solutions as a (one-parameter) family and then use  (sin( 2(s L1) 1) sin 1)  κ2 the minimum curvature variation criterion to find the ≤ ≤ + optimal biarc interpolation.  for L1 s L1 L2,   1  = − κ + θ − θ Problem Statement: Given two point-tangent pairs, y(s) y0 κ (cos( 1 L1 0) cos 0)  1 C (x , y ,θ ) and C (x , y ,θ ),8 find the smoothest  1 0 0 0 0 2 2 2 2  − κ − + θ − θ biarc (x , y ,θ ,κ , L ,κ , L ) which passes through κ (cos( 2(s L1) 1) cos 1) 0 0 0 1 1 2 2 2 said points at their respective tangents. (22) Proposition 5. Consider two endpoints with associ- where θ1 is the tangent angle at the join between the ated tangents C0(x0, y0,θ0) and C2(x2, y2,θ2), and de- iψ biarc’s constituent circular arcs. This angle can be de- note C2 − C0 = L0e as before. Then, the set of biarcs 170 Kimia, Frankel and Popescu

which satisfy these boundary conditions can be param- On the other hand, if κ1 = κ2, then θ0 = θ2,ψ = θ +θ ,κ , 0 2 eterized by the curvature of the first arc 1 where the 2 and the biarc degenerates to a single arc with remaining parameters (κ2, L1, L2) are analytically de- curvature and length rived separately for four conditions: 2 θ2 − θ0 κ1 = κ2 = sin , L0 2 (i) κ1 = κ2 = 0; this happens only if θ0 = θ2 = ψ   θ −θ = + = 2 0 and L L1 L2 L0; = + =  2 . L L1 L2 L0 θ −θ (28) (ii) κ1 = 0,κ2 = 0. In this case,θ0 = θ2,θ0 = ψ, and 2 0 sin 2   θ −θ − sin2 2 0 Proof: Since the constraints pertaining to the initial κ = 2 2 , 2 θ − ψ oriented point C are implicitly satisfied by the forward L0 sin( 0 )  0 θ +θ construction of the biarc, those pertaining to C are sin 2 0 − ψ 2 = 2  L1 L0 θ −θ (24) satisfied when the coordinates defined by Eq. (22) at L sin 0 2 2 are (x2, y2) and the tangent angle defined by Eq. (23) θ − θ 2 0 at L = L1 + L2 is θ2. First, when κ1 = 0 and κ2 = 0 L2 = + 2nπ, κ2    = + 1 κ + θ − θ x2 x0 (sin( 1 L1 0) sin 0) where n is chosen to give the smallest positive L2;  κ1 κ = κ = θ = θ θ = ψ  1 (iii) 1 0, 2 0; we have 0 2, 2 and  + θ − κ + θ  κ (sin 2 sin( 1 L1 0))   2 θ −θ 1 2 sin2 2 0  = − κ + θ − θ (29) κ = 2 y2 y0 κ (cos( 1 L1 0) cos 0) 1 θ − ψ  1 sin( 2 )  1  − (cos θ − cos(κ L + θ )) θ2 − θ0  κ 2 1 1 0 = + π,  2 L1 κ 2n (25) θ = κ + κ + θ . 1   2 2π 2 L2 1 L1 0 θ +θ 2 0 − ψ sin 2 L2 = L0   , θ0−θ2 The set of three equations in Eq. (29) constrains the sin 2 four unknowns (κ1, L1,κ2, L2) but lacks one equation to solve for them. However, the set of solutions can where n is chosen to give the smallest positive L . 1 be characterized by parameterizing them in terms of (iv) κ = 0 and κ = 0; In this case, if κ = κ , then 1 2 1 2 some variable. Observe an interesting asymmetry in not all θ0,θ2,ψ are equal and the relationships among κ1, L1,κ2, L2, namely, that κ1   and κ2 correlate independently of L1 and L2. Assuming 2 θ2−θ0 2 −2 sin + κ1 L0 sin(θ2 − ψ) κ = 2 , κ1 = κ2, 2 L 2 sin(θ − ψ) + κ L 0 0 1 0  θ1 − θ0 + 2n1π  1 1 = ,  − + θ − θ L1 κ (26) (x2 x0) sin 0 sin 2 1  κ κ  1 2 θ2 − θ1 + 2n2π  L = ,  1 1 2  = − sin θ1 κ2 κ κ 1 2  (30)  − − 1 θ − 1 θ where n1 and n2 are chosen to give the smallest (y2 y0) cos 0 cos 2  κ1 κ2 positive L1 and L2, respectively, and where θ1 is   defined as:  1 1  =− − cos θ1. κ1 κ2  κ κ − + κ θ − κ θ  1 2 (x2 x0) 2 sin 0 1 sin 2 κ = κ = κ = κ sin θ1 = In the general case when 1 0, 2 0, and 1 2, κ2 − κ1 κ1 can be chosen as the independent parameter, and  −κ κ − + κ θ − κ θ  1 2 (y2 y0) 2 cos 0 1 cos 2 κ2, L1, L2 can be found as functions of κ1. Special cases cos θ1 = . κ2 − κ1 which violate one or more of these conditions are also (27) handled after considering the general case. Euler Spiral for Shape Completion 171

First, in the general case θ1 can be eliminated from We now consider a special case where κ1 = κ2 = 0. Eq. (30) From Eq. (29) we have   1 2  − = − θ + θ 1 1 x2 x0 ( sin 0 sin 2)κ (x − x ) + sin θ − sin θ 2 2 0 κ 0 κ 2  (35) 1 2  1 2 y2 − y0 = (cos θ0 − cos θ2) 1 1 κ2 + (y2 − y0) − cos θ0 − cos θ2 κ1 κ2 Note that this implies θ = θ , since the points C 1 1 2 0 2 0 = − . and C are distinct. Recall that (x − x , y − y ) = κ κ 2 2 0 2 0 1 2 L0(cos ψ, sin ψ), so that Eq. (35) can be rewritten as  θ − θ θ + θ − = ψ −  2 2 0 2 0 Expanding, and using x2 x0 L0 cos and y2 L cos ψ = sin cos = ψ κ κ 0 κ 2 2 y0 L0 sin , we solve for 2 in terms of 0, 2 (36)  2 θ − θ θ + θ   L sin ψ = sin 2 0 sin 2 0 2 θ −θ 0 −2 sin 2 0 + κ L sin(θ − ψ) κ2 2 2 κ = 2 2 1 0 2 2 θ − ψ + κ (31) L0 2 sin( 0 ) 1 L0 θ +θ ψ = 2 0 or, equivalently, tan tan 2 . It follows that to κ κ have equal curvatures κ1 and κ2, i.e, when the biarc Thus, 2 is computable in terms of 1 independent of L1 θ +θ −2 degenerates to a circular arc, we must have ψ = 0 2 + or L2. Note that when κ1 = sin(θ0 − ψ), |κ2|=∞. 2 L0 nπ. Note that when θ + θ = π, the same relationship Equation (30) also solves for θ1, in terms of κ1 0 2 holds. Substituting back into Eq. (36) gives:   κ κ (x − x ) + κ sin θ − κ sin θ  sin θ = 1 2 2 0 2 0 1 2  θ + θ 1 κ − κ  − n 0 2 2 1 ( 1) L0 cos  −κ κ − + κ θ − κ θ  2  θ = 1 2 (y2 y0) 2 cos 0 1 cos 2 ,  cos 1  2 θ2 − θ0 θ0 + θ2 κ2 − κ1  = sin cos κ 2 2 (32) 2 (37)  θ + θ (−1)n L sin 0 2  0 Since θ = κ L + θ + 2n π, multiple solutions are  2 1 1 1 0 1  θ − θ θ + θ  2 2 0 0 2 possible corresponding to arcs which wind more than  = sin sin 2π. We seek the smallest positive L1 by selecting n1 κ2 2 2 as follows, Thus,   = θ − θ > κ > θ − θ n1 0 1 0 0 and 1 0 n 2 2 0  κ1 = κ2 = (−1) sin , (38) n1 =+1 θ1 − θ0 > 0 and κ1 < 0 L0 2 (33) n =−1 θ − θ < 0 and κ > 0  1 1 0 1 ψ = θ − θ < κ < . where n is decided from the relationship between n1 0 1 0 0 and 1 0 θ0+θ2 and 2 . The lengths are obtained from Eq. (29), Similarly, θ = κ (L + L ) + θ 2 1 1 2 0 θ − θ θ − θ + 2n π n 2 2 0 2 1 2 = (−1) sin (L1 + L2) + θ0. L2 = , (34) L0 2 κ2 Thus, the total length is which solves for L2 in the manner described above. In κ , ,   summary, Eqs. (31) through 34 solve for 2 L1 L2 in θ −θ κ κ = ,κ = κ = κ L (−1)n 2 0 terms of 1, when 1 0 2 0 and 1 2, and = + = 0  2  . L L1 L2 θ −θ (39) 2 2 0 ensure that all the constraints in Eq. (29) are met. sin 2 172 Kimia, Frankel and Popescu

θ0+θ2 Since L must be positive, this further constrains the (c) if θ0 = θ2 and ψ = , then the biarc degener- ψ θ θ 2 required relationship among , 0 and 2 when curva- ates to an arc,κ1 = κ2 and Eq. (28) of case (iv) tures are equal, namely n = 0: applies; θ +θ θ = θ ψ = 0 2 + π, θ −θ (d) if 0 2 and n then 2 0 2 θ2−θ0 2 (i) if θ2 −θ0 > 0 then 0 < <πand θ −θ > 0 2 sin 2 0 (d.1) if ψ = θ , cases (iii) and (iv) are possible, requiring n = 0; 2 0 θ −θ (d.2) if ψ = θ , cases (ii) and (iv) are both (ii) if θ − θ < 0 then −π< 2 0 < 0 and 2 θ −θ 2 0 2 2 0 possible, and 2 θ −θ > 0 requiring n = 0. 2 0 (d.3) if ψ = θ and ψ = θ , then cases (ii), (iii) sin 2 0 2 and (iv) are all possible. θ0+θ2 2 θ2−θ0 Hence, ψ = , and κ1 = κ2 = sin , L = θ −θ 2 L0 2 2 0 L0 2 θ −θ . 2 2 0 4.3. Optimal Biarc Interpolation sin 2 Note, further, that in the limit as θ2 = θ0, then κ2 = κ = + = 1 0 (straight line) and L1 L2 L0, as expected. Proposition 4 characterizes the set of biarcs satisfying This completes the proof of case (iv). the point-tangent boundary conditions. The selection κ = Let’s now consider the special case (ii) when 1 0, of the optimal biarc requires an additional constraint. κ = 2 0. Equation (29) gives In contrast to Ullman’s constraint of minimizing total  squared curvature, we will use the constraint of mini-  sin θ − sin θ  = + θ + 2 0 mizing the total curvature variation, Eq. (3). Since the x2 x0 L1 cos 0 κ 2 circular arcs themselves have no curvature variation,  θ − θ (40)  = + θ − cos 2 cos 0 , minimizing the integral in Eq. (3) is tantamount to min- y2 y0 L1 sin 0 κ − κ 2 κ2 imizing the difference in arc curvatures ( 2 1) at the point joining them. which gives two equations in two unknowns L1 and κ2. If θ = θ , this equation requires ψ = θ , which forces 2 0 0 Proposition 6. The optimal biarc, i.e., the biarc min- κ1 = κ2 = 0, thus violating this case’s assumption. 2 imizing total curvature variation E = (κ2 − κ1) , and Thus, θ2 = θ0. Similarly, ψ = θ0 leads to θ2 = θ0,so satisfying endpoint tangent conditions C0(x0, y0,θ0) this is also not possible. Eliminating κ2 from Eq. (40) and C2(x2, y2,θ2) is specified as follows: and solving for L leads to θ +θ ψ = 0 2   (a) if 2 then the optimal biarc degenerates to θ +θ sin 0 2 − ψ a circular arc = 2  . L1 L0 θ −θ (41) sin 2 0 2 2 θ2 − θ0 κ1 = κ2 = sin , (43) L0 2 The expression for κ2 is then either derived from the limiting case of Eq. (31) or directly by eliminating L 1 with E = 0. The approximation for L when θ = in Eq. (40) as: 0 θ , is   2 2 θ2−θ0 −2 sin θ −θ κ = 2 . (42) 2 0 2 θ − ψ 2 L0 sin( 0 ) L = L1 + L2 = L0  , (44) θ2−θ0 sin 2 The third case (iii) is handled similarly. Finally, in κ = κ = case (i), when 1 2 0, the biarc degenerates while, if θ0 = θ2, then L = L0. θ +θ θ = θ = ψ 0 2 to a single line requiring 0 2 . In this case, (b) if ψ = and θ0 = θ2, then two extremal solu- = + = . 2 L L1 L2 L0 This completes the proof in all tions exist. When |θ2 − θ0| >πthe solution is cases.  − θ + θ θ − θ ,  4 3 0 2 2 0 Corollary 1. Given the conditions of Proposition 4 κ1 = sin − ψ cos we have the following cases: L0 4 4  4 θ + 3θ θ − θ (a) if θ0 = θ2 = ψ then κ0 = κ2 = 0 and L = L0;  0 2 2 0 κ2 = sin − ψ cos , (b) if θ0 = θ2 = ψ then only case (iv) applies with L0 4 4 θ0 = θ2. (45) Euler Spiral for Shape Completion 173

θ −θ θ +θ = 64 4 2 0 2 0 2 −ψ , leading to two solutions with E1 L2 cos ( 4 ) sin ( 2 ) and with 0 < |θ − L1 and L2 specified by Eq. (26). When 0 2   θ0+θ2 θ0| <π 2 sin − ψ 2 =±1. (49)  2 sin(θ − ψ) + κ L θ + θ θ − θ 0 1 0  4 3 0 2 2 0 κ1 = cos − ψ sin L0 4 4 The first solution corresponding to the negative sign is  θ + θ θ − θ κ = 4 0 3 2 − ψ 2 0 , 2 cos sin 2 θ + θ L0 4 4 0 2 κ1 =− sin − ψ + sin(θ0 − ψ) (46) L0 2

θ −θ θ +θ θ + θ θ − θ 64 4 2 0 2 ( 0 2) −ψ , 4 3 0 2 2 0 with E2 = L2 sin ( 4 ) sin ( 2 ) and with =− sin − ψ cos (50) 0 L 4 4 L1 and L2 obtained from Eq. (26). 0 θ +θ (c) if ψ = 0 2 and θ = θ , then the solution is an 2 0 2 κ “S-curve”, From this value for 1 and from Eq. (31), and some  more manipulation, − κ = 4 θ − ψ  1 sin( 0 ) 4 θ + 3θ θ − θ L0 κ = sin 0 2 − ψ cos 2 0 . (51)  (47) 2 L 4 4  4 0 κ2 = sin(θ0 − ψ), L0 Note that in this case = 64 2 θ − ψ with E L2 sin ( 0 ). θ − θ θ + θ 0 8 2 2 0 0 2 κ2 − κ1 = cos sin − ψ . L0 4 2 θ +θ ψ = 0 2 Proof: First, in case(a) where 2 , from Propo- (52) sition 3 cases (i) and the second part of (iv) are valid, and the family of biarcs degenerates to a single arc so- θ = θ κ = κ = Similarly, the second solution corresponding to the pos- lution: if 0 2 this is a straight line 1 2 0; itive sign in Eq. (49) gives otherwise, if θ0 = θ2, curvatures of the arc are obtained from Eq. (28). Thus the optimal biarc is the only biarc.  θ +θ 4 3θ0 + θ2 θ2 − θ0 ψ = 0 2 . κ = − ψ , Second, consider the case where 2 Then,  1 cos sin curvature κ can be written as in Eq. (26) covering not L0 4 4 2  θ + θ θ − θ (53) only the first part of case (iv) but also cases (ii) and  4 0 3 2 2 0 κ2 = cos − ψ sin . (iii) as special cases. Note that in all cases κ1 = κ2. L0 4 4 2 Analytically, optimizing E = (κ2 − κ1) requires that dE = κ − κ d κ − κ = κ 0, or 2( 2 1) κ ( 2 1) 0 which can For this second solution, d 1 κ d 1 d 2 = happen only if κ 1, d 1 θ − θ θ + θ κ − κ =− 8 2 2 0 0 2 − ψ . κ 2 1 sin sin d 2 = 2 1 θ − ψ L0 4 2 2 L0 sin( 2 ) dκ1 L0 (2 sin(θ0 − ψ) + κ1 L0) (54)

× (2 sin(θ0 − ψ) + κ1 L0) Having characterized the only two solutions at which − L (−1 + cos(θ − θ ) + κ L sin(θ − ψ)) 0 2 0 1 0 2 the derivative of E is zero, we now examine whether 2 2 these extrema are minima, by verifying that dE > 0. = dκ12 2 (2 sin(θ0 − ψ) + κ1 L0) Since × (2 sin(θ − ψ) sin(θ − ψ) 2 0 2 2 2 d E dκ2 d κ2 + − θ − θ = 2 − 1 + 2(κ2 − κ1) , (55) 1 cos( 2 0)) κ2 κ 2κ   d 1 d 1 d 1 θ +θ 2 sin 0 2 − ψ 2 d2κ = 2 , (48) = 2(κ − κ ) 2 . (56) θ − ψ + κ 2 1 2 2 sin( 0 ) 1 L0 d κ1 174 Kimia, Frankel and Popescu

Taking second derivatives using Eq. (48) and then using A similar argument for κ2 shows that the limit of Eq. (49), κ2 is the limit of κ1. On the other hand, if κ1 = θ +θ   κ , suppose ψ = 0 2 . Then, for the first solution θ +θ 2 2 2 2 0 2 − ψ θ +θ θ −θ d κ2 4sin 2 sin( 0 2 − ψ) cos( 2 0 ) = 0. Since both θ and θ =−2L 2 2 4 0 2 2 0 3 , π d κ1 (2 sin(θ0 − ψ) + κ1 L0) are in the range [0 2 ), the only term which can be θ +θ θ +θ − zero is sin( 0 2 − ψ), and therefore ψ = 2 0 + nπ. =±  L0 . 2 2 θ +θ (57) sin 0 2 − ψ In order to have positive length, n must be zero. A 2 similar argument holds for the second solution. Thus, θ +θ 2 ψ = 2 0 , d E = 2 a contradiction, and the tangents must be Now for the first solution, we obtain 2 d κ1 θ −θ 2 co-circular. 2 2 0 d E = 16cos ( 4 ) while for the second solution d2κ θ −θ 1 16 sin2( 2 0 ). 4 The pseudocode for biarc interpolation is described We conclude that the solutions are local minima, ex- in Appendix A.1. cept possibly for the second solution when θ0 = θ2. This special case is considered below. The global min- imum is the choice between the two with a lower θ −θ = κ −κ 2 |θ −θ | <π 2 2 0 < 5. Examples E ( 2 1) . Thus, when 2 0 , sin ( 4 ) 2 θ2−θ0 cos ( 4 ) and the second solution is the lower mini- mum, while when |θ2 − θ0| >π, the first solution is In this section we examine the Euler spiral comple- the better one. tion curve for a variety of point-tangent configurations, Finally, consider the special case when θ0 = θ2. The probe the extensibility property of the Euler Spiral, and first solution corresponding to the negative sign is apply the results to the examples presented in the in- troduction, Fig. 1. We will then describe how this ap- −4 κ = sin(θ − ψ), proach may be used in several computer vision tasks, 1 L 0 0 (58) specifically, disambiguating edge maps in perceptual 4 grouping, partitioning visual form, and the filling-in of κ2 = sin(θ0 − ψ), L0 occluded areas. The completion curve is derived by analytically find- which corresponds to an “S-shaped curve” biarc con- ing the optimal biarc as described in Section 4, and then sisting of two identical arcs of equal curvature but op- using gradient descent using the biarc as the initial con- posite sign. In this case dition to solve the nonlinear optimization described in Section 2 (see also Appendix A.2), as demonstrated in 8 Fig. 10. κ2 − κ1 = sin(θ0 − ψ). (59) L0 The completion curve is shown for a variety of point- tangent pair configurations in Fig. 11. A subjective ex-

The second solution gives κ1 = 0 and κ2 = 0, but amination reveals that the completion curve is intuitive 9 the latter violates the assumption that κ1 = κ2. and natural. Figure 12 shows this completion curve when overlayed on synthetic occluders; both the fi- Corollary 2. The optimal biarc interpolating be- nal Euler spiral and the intermediate biarc are shown; C , ,θ C , ,θ tween 0(x0 y0 0) and 2(x2 y2 2) degenerates to observe that the biarc is a good approximation of the a circular arc if and only if the point-tangent pairs are Euler spiral. Figure 13 shows the completion curve for co-circular. the Kanizsa illusory contour, the occluded kangaroo, and for other shapes. Proof: When two tangents lie on a circle, ψ = θ0 + θ −θ θ +θ 2 0 = 2 0 , and we have a single arc. We can also The extensibility property of the completion curve is 2 2 θ +θ examined in Fig. 14. Observe that the numerically de- check the limiting case of the solution as ψ → 0 2 2 rived completion curve satisfies the extensibility prop- erty as predicted by the theoretical results. Extensibility − θ + θ θ + θ θ − θ 4 3 0 2 2 0 2 0 of the completion contour is critical in the completion κ1 = sin − cos L0 4 2 4 of a boundary behind an occluder, i.e., the comple- 2 (θ − θ ) tion curve remains stable with changes in the extent =± sin 2 0 . L0 2 of the occlusion. Note that elastica are extensible, but Euler Spiral for Shape Completion 175

edge maps in perceptual grouping. Since edge detection algorithms often result in imperfect edge maps con- taining numerous gaps, spurious edges, etc., percep- tual grouping is required to disambiguate the edge map by taking into account structural saliency. There are a large number of approaches for accomplishing this. Williams and Thornber (1999) note that in gen- Figure 10. Two examples of how the initial biarc (in cyan and eral these approaches involve two steps of first com- magenta), gives rise to a series of Euler Spirals which converge to puting a local affinity measure for a pair of edges, the Euler Spiral (in blue) using gradient descent. The intermediate spirals are in red. and then computing a global saliency measure by optimizing support over various curve hypotheses (Guy and Medioni, 1992; Herault and Horaud, 1993; Parent and Zucker, 1989; Sarkar and Boyer, 1992; are not stable with changes in scale. In contrast, scale- Sharon et al., to appear; Williams and Jacobs, 1997; invariant version of elastica are stable with change in Williams and Thornber, 1999). While previous ap- scale, but are not extensible. The Euler Spiral solution proaches have used cocircularity (Parent and Zucker, is stable with changes in the extent of occlusion and 1989), and the total curvature of elastical completion extensible with changes in scale. curves, we propose that the local affinity measure can The question naturally arises that while these com- instead be based on the properties of the Euler spi- pletions appear intuitive, what role if any can they can ral, as used in Johannes et al. (2001) and depicted in potentially play in actual computations required for Fig. 15. various computer vision tasks. We now describe three While all the information pertaining to these prop- potential uses of the Euler spiral completion curves in erties is already implicit in the part-tangent pairs, the this context. First, consider the task of disambiguating computation of the completion curve properties e.g.,

9 6 8 10 8 10 11 12 10 12 13 12 14 14 15 14 16 16 16 17 18 18 18 19 20 20 6 8 10 12 14 16 18 20 22 6 8 10 12 14 16 18 20 22 6 8 10 12 14 16 18 20 22 6 6 2

4 8 8 6 10 10 8

12 12 10

14 14 12 14 16 16 16 18 18 18

20 20 20 6 8 10 12 14 16 18 20 22 6 8 10 12 14 16 18 20 22 6 8 10 12 14 16 18 20 22

Figure 11. The interpolation of a pair of point-tangent pairs by the Euler Spiral. The first point and its tangent are held constant for each graph while varying the position and tangent at the second point. Note that the entire space of variations can be described by two parameters, i.e., the angle of each tangent with respect to the line connecting them. However, we show examples in this extrinsic setting as the variation at end points is exactly what arises in visual situations. Observe that the completions are visually intuitive. 176 Kimia, Frankel and Popescu

Figure 12. From left to right, original image, occluded object, biarc completion of the simulated occlusion, Euler spiral refinement of the biarc completion.

Figure 13. The completion curve for several examples including two of the examples presented in Fig. 1. of curvature variation γ , currently requires the explicit Second, consider the task of partitioning visual form. reconstruction of the Euler spiral through the biarc While boundary-based approaches partition the silhou- as described in Section 4. Furthermore, in connecting ettes based on salient features such as negative cur- two edges, one must verify that the completion curve vature extrema (Hoffman and Richards, 1985), some does not intersect with the existing edges or previously region-based schemes look for the suitability of actual established completion contours, thus arguing for the “break curves” through the shape which are anchored explicit reconstruction of the Euler spiral, rather than at these salient features (Siddiqi and Kimia, 1995). just deriving these properties from the point-tangent Specifically, ambiguous partitioning hypotheses can be pairs. disambiguated using a measure of part-curve saliency, Euler Spiral for Shape Completion 177

Figure 14. Two examples illustrating that the Euler Spiral is extensible. The blue portion is the interpolation starting with the middle point. Extensibility is critical since the interpolation must be stable with changes in the extent of occlusion.

Figure 15.A“circular” shape is embedded among spurious edges. The sequence of operations that either removes an edge or groups it with others is generated by a gradient descent on an energy functional which is based on the energy of the Euler Spiral interpolation between neighboring edge elements (Johannes et al., 2001). The additional curves are the medial axis which indicate which pairs of point-tangent pairs should be considered at each step.

Fig. 16. While the original approach used part-lines to 6. Summary and Discussion test the inclusion of the break curves inside the shape and splines to measure the total curvature, the Euler The class of curves which interpolate two point-tangent spiral completions are more appropriate to use in both pairs, i.e., by passing through each point with specified tasks (Dhandapani and Kimia, 2002). Again, in analogy tangents, is rather large. Thus, some criterion is re- to the edge map disambiguation, while this information quired to pick the most suitable curve to interpolate is implicit in the point-tangent pairs, its computation between them. Previously, several measures of opti- requires an explicit reconstruction to check that hy- mality have been proposed that attempt to capture our pothesized break-curves do not intersect the boundary sense of aesthetics and how pleasing the interpolation of the shape. curve appears. In addition, in previous approaches re- The third example is based on object completion stricted classes of curves such as biarcs or cubic splines behind an occluder, e.g., as required in in-painting. have been identified that render the optimization The current approach to in-painting interpolates in- practical. tensities in the missing region, thus effectively diffus- Despite such ambiguity and the apparent lack of ing boundary intensities within that region. This ap- guidelines in the selection of an optimality measure proach, however, will fail when the missing region and an appropriate class of curves, the problem is con- contains boundaries, as in Fig. 17, where diffusion- strained by several required properties of visual in- based inpainting smears two different regions together, terpolation. These properties were partially identified Fig. 17(c). The explicit reconstruction of the missing by Ullman (1976) as axioms, and more completely boundary prior to the diffusion process, however, pre- by Knuth (1979). Unfortunately, the latter set of pro- vents this, Fig. 17(d). posed axioms is not consistent. Knuth, given the choice 178 Kimia, Frankel and Popescu

Figure 16. This figure from (Siddiqi and Kimia, 1995) illustrates how stable partitioning can arise from disambiguating competing part-curve hypotheses. (a) original shape; (b) all part-curve hypotheses; (c) disambiguation using the saliency of the part-curve; (d) partitioning results. The Euler Spiral provides a better break curve and a better saliency measure (Dhandapani and Kimia, 2002). between locality and extensibility, to make this set con- over a complete range and combinations of boundary sistent, reluctantly drops extensibility. This solution vi- data; (v) the internal parameters of the interpolant are olates roundedness. On the other hand, in this paper geometrically meaningful and thus can be used as an in- we examine the implications of retaining extensibility dicator to dis-ambiguate edges in perceptual grouping, and dropping locality instead. This allows us to main- as suggested in (Guy and Medioni, 1992; Parent and tain roundedness, i.e., circular interpolations of point Zucker, 1989; Sha’ashua and Ullman, 1988; Williams tangent pairs that are indeed on a circle. This in turn and Jacobs, 1995). Thus, it provides a suitable solution leads to an energy functional which penalizes curvature to the gap completion and boundary modeling prob- variation, but not curvature proper. The solution yields lems as used in the context of perceptual grouping of interpolations which are segments of the Euler Spiral, edge maps, partitioning visual form, and filling-in of i.e., curves where curvature varies linearly with ar- occluded objects among others. clength. The rest of the paper deals with the derivation of analytic formulas for computing this curve using a biarc approximation which can then be refined to obtain Appendix A: Algorithm the Euler spiral by solving a nonlinear system of two equations in two unknowns involving Fresnel Integrals. We now describe the algorithms in pseudocode for- The practical advantages of using an Euler spi- mat for computing the parameters of the biarc, which ral interpolation are: (i) fast and reliable completion has minimum total curvature derivative variation, and curve computation; (ii) natural and intuitive comple- for computing the parameters of the Euler Spiral. Let tion curves; (iii) robustness to changes in the extent (x0, y0,θ0) and (x2, y2,θ2) denote the initial and final of occlusion: extensibility ensures that as a portion of coordinate-tangent angle pairs. The biarc algorithm re- the occluded contour modeled by an Euler spiral is re- turns K1, L1, K2, L2, the curvature and length of each vealed the interpolation does not change. This property arc as well as the total curvature variation E. The Euler is not true of the Ullman’s biarc or our biarcs, nor of the Spiral algorithm returns the initial and final curvature scale-invariant elastica (regular elastica are extensible K0, K2, the length L, the rate of change of curvature but change with scale); (iv) the Euler Spiral interpolates γ , and the total curvature derivative variation E.

Figure 17. (a) The original image, (b) The gap (in brown), (c) Inpainting using a conventional diffusion based technique, and (d) Inpainting using the Euler Spiral (in red) as the completion contour of the occluded object. Euler Spiral for Shape Completion 179

A.1. Pseudocode for Biarc Implementation

COMPUTEBIARCSOLUTION(x0, y0, x2, y2,θ0,θ2) 58 1 59 else 2 2 2 L ← (x1 − x0) + (y1 − y0) 60 L3 ← ComputeArclength 3 ψ ← AngleOfVector(x2 − x0, y2 − y0) 61 (θ0,θjoin,κ3) 4 smallAngle ← 0.001 62 5 smallCurvature ← 0.001 63 if κ4 == 0 6 biarcflag ← 0 64 then sin((θ2+θ0)/2−ψ) 7 L1 ←−10 65 L4 ← L sin((θ0−θ2)/2) 8 L2 ←−10 66 θ +θ ψ − ( 2 0) π = 9 if ( ( 2 )mod 0) 67 else 10 then if ψ − θ0 = 0 68 L4 ← ComputeArclength 11 then 69 (θ join,θ2,κ4) 12 κ1 ← 0 70 13 κ2 ← κ1 71 14 L1 ← L/2 72 15 L2 ← L1 73 E1 ← (κ2 − κ1)(κ2 − κ1) 16 74 E2 ← (κ3 − κ4)(κ3 − κ4) 17 else 75 estimateL , estimateK to be computed according θ −θ κ ← −2 2 0 18 1 L sin 2 76 to correct criteria for choosing one of the two solutions 19 κ2 ← κ1 77 if L1 + L2 < L3 + L4 π/2−θ0 20 L1 ←|θ0 L sin | 78 then sin(2∗θ0) 21 L2 ← L1 79 estimateL ← L1 + L2 22 80 estimateK ← κ1 23 θjoin ← θ2 81 else 24 estimateK ← κ1 82 estimateL ← L3 + L4 25 estimateL ← L1 + L2 83 estimateK ← κ3 26 84 return estimateK , estimateL 27 else 85 28 biarcflag ← 1 θ +θ θ −θ κ ←−4 3 0 2 − ψ 2 0 29 1 L sin( 4 ) cos( 4 ) 4 θ0+3θ2 θ2−θ0 30 κ2 ← sin( − ψ) cos( ) L 4 4 ANGLEOFVECTOR(X, Y ) 31 θ join ← ComputeJoinTheta , ,θ , , ,θ ,κ ,κ 1 32 (x0 y0 0 x2 y2 2 1 2) v = Y κ == 2 alangle arctan2 X 33 if 1 0 < (sin((θ2+θ0)/2−ψ) 3 if valangle 0 34 then L1 ← L θ −θ / sin(( 0 2) 2)) 4 then 35 5 val ← (val + 2π) 36 else angle angle 6 37 L ← ComputeArclength(θ ,θ ,κ ) 1 0 join 1 7 return val 38 angle 39 if κ2 == 0 sin((θ2+θ0)/2−ψ) 40 then L2 ← L sin((θ0−θ2)/2) 41 COMPUTEJOINTHETA(x0, y0,θ0, x2, y2,θ2,κ1,κ2) κ1κ2(x2−x0)+κ2 sin(θ0)−κ1 sin(θ2) 42 else 1 sin(θJoin) ← κ2−κ1 ← θ ,θ ,κ −κ1κ2(y2−y0)+κ2 cos(θ0)−κ1 cos(θ2) 43 L2 ComputeArclength( join 2 2) 2 cos(θJoin) ← κ −κ 44 θ ← 2 θ 1 , θ θ +θ θ −θ 3 Join AngleOfVector(sin( Join) cos( Join)) κ ← 4 3 0 2 − ψ 2 0 45 3 cos( ) sin( ) 4 return θ L θ +4 θ θ −4 θ Join κ ← 4 0 3 2 − ψ 2 0 46 4 L cos( 4 ) sin( 4 ) 47 if (κ3 == 0)and(κ4 == 0)

48 then Both curvatures are 0—e-approximations COMPUTEARCLENGTH(θ0,θ1, k) 49 needed 1 numerator ← θ1 − θ0 50 else 2 if (k < 0)and((θ1 − θ0) > 0) κ = κ 51 if ( 3 4) 3 then numerator ← (numerator − 2π) 52 then 4 θ ← 53 join ComputeJoinTheta 5 else if (k > 0)and((θ1 − θ0) < 0) , ,θ , , ,θ ,κ ,κ 54 (x0 y0 0 x2 y2 2 3 4) 6 then numerator ← (numerator + 2π) κ == 55 if 3 0 7 56 then 8 return numerator sin((θ2+θ0)/2−ψ) k 57 L3 ← L sin((θ2−θ0)/2) 9 180 Kimia, Frankel and Popescu

A.2. Pseudocode for the Euler spiral

SOLVEEULER(x0, y0,θ0, x2, y2,θ2, iternum) 41 curEstL ← (curEstL + errorStep) 1 estKinit, estLinit ← ComputeInitialEstimates 42 2(x0, y0,θ0, x2, y2,θ2) 43 else if curEstL > errorStep 3 κfin, Lfin ← SolveIteratively 44 then 4(x0, y0,θ0, x2, y2,θ2, estKinit, estLinit, iternum) 45 curEstL ← (curEstL − errorStep) θ −θ − κ γ ← 2 0 ( finL fin) 5 2 L ,2 46 fin ← 6 return κfin, Lfin,γ 47 prevError error

, ,θ , , ,θ ,κ, COMPUTEINITIALESTIMATES(x0, y0,θ0, x2, y2,θ2) COMPUTEERROR(x0 y0 0 x2 y2 2 L) θ −θ − κ , ← γ ← 2 0 ( L) 1 estKinit estLinit ComputeBiarcSolution 1 2 2 , ← L , ,θ ,κ,γ, 2(x0, y0,θ0, x2, y2,θ2) 2 X Y EulerSpiralEndPoint(x0 y0 0 L) = − 2 + − 2 3 return estKinit, estLinit 3 error (X x2) (Y y2) 4 4 return error

, ,θ,κ,γ, SOLVEITERATIVELY(x0, y0,θ0, x1, y1,θ2, estKinit, estLinit, iternum) EULERSPIRALENDPOINT(a b s) 1 error ← computeError 1 = 0.00000001 γ> γ< γ< γ> 2(x0, y0,θ0, x1, y1,θ2, estKinit, estLinit) 2 if ( 0and )or( 0and ) 3 prevError ← 1000 3 then 4 errorStep ← 0.1 4 γ ← 0 5 epsilon ← 0.00001 5 if γ>0 6 epsilonError ← 0.1 6 then ← ← κ√+(γ s) 7 curEstK estKinit 7 first fresnel( πγ ) ( )κ 8 curEstL ← estL 8 second ← fresnel( √ ) init (πγ) 9 for i ← 0 to iternum 9 A ← first[0] − second[0] 10 do 10 B ← first[1] − second[1] 11 if (error < epsilon)or(i == iter − 1) ← θ − κ2 num 11 cosTerm cos( 2γ ) 12 then ← θ − κ2 12 sinTerm sin( 2γ ) 13 return curEstL, curEstK √ π 13 constTerm = ( ) 14 γ 14 X ← a + (constTerm)(cosTermA − sinTermB) 15 else 15 Y ← b + (constTerm) ∗ (sinTermA + cosTermB) 16 error ← computerror 0 16 if γ<0 17 (x , y ,θ , x , y ,θ , (curEstK + errorStep), curEstL) 0 0 0 1 1 2 17 then 18 error ← computeError −κ+ −γ 1 18 first ← fresnel( √ ( s) ) , ,θ , , ,θ , − , (−πγ) 19 (x0 y0 0 x1 y1 2 (curEstK errorStep) curEstL) −κ 19 second ← fresnel( √ ) 20 error ← computeError (−πγ) 2 ← − 21 (x , y ,θ , x , y ,θ , curEstK, (curEstL + errorStep)) 20 A first[0] second[0] 0 0 0 1 1 2 ←− − 22 if estL > errorStep 21 B (first[1] second[1]) ← π 23 then 22 constTerm ( −γ ) 24 estL ← (curEstL − errorStep) 23 cosTerm = cos(θ − (κ2)/(2γ )) 2 25 error3 ← computeError 24 sinTerm = sin(θ − (κ )/(2γ )) 26 (x0, y0,θ0, x1, y1,θ2, curEstK, estL) 25 X ← a + (constTerm)(cosTermA − sinTermB) 27 error ← min(error0, error1, error2, error3) 26 Y ← b + (constTerm)(sinTermA + cosTermB) 28 if error >= prevError 27 ← errorStep γ = 29 then errorStep 2 28 if 0 30 29 then 31 else if error == error0 30 if κ = 0 32 then 31 then 33 curEstK ← (curEstK + errorStep) 32 X ← a + scos(θ) 34 33 Y ← b + ssin(θ) 35 else if error == error1 34 ← 1.0 36 then 35 else constTerm kappa 37 curEstK ← (curEstK − errorStep) 36 X ← a + (constTerm)(sin(κs + θ) − sin(θ)) 38 37 Y ← b + (−constTerm)(cos(κs + θ) − cos(θ)) 39 else if error == error2 38 return X, Y 40 then Euler Spiral for Shape Completion 181

Acknowledgments References

This material is based upon work supported by the Abramowitz, M. and Stegun, I.A. (eds.) 1972. Handbook of Math- National Science Foundation under grant 0083231. ematical Functions with Formulas, Graphics, and Mathematical Any opinions, findings, and conclusions or recommen- Tables. National Bureau of Standards, New York. Ahlberg, J., Nilson, E., and Walsh, J. 1967. The Theory of Splines dations expressed are those of the authors and do not and their applications. New York, Academic Press. necessarily reflect the views of the National Science Baldwin, A. 1996. Teardrop & clothoid loops. www.demon.co. Foundation. uk/arvis/wwg/tech/phtd.html. Birkhoff, G. and Boor, C.D. 1965. Piecewise polynomial interpola- tion and approximation. Approximations of Functions. Notes Brady, M. and Grimson, W. 1980. Shape encoding and subjective contours. In Proc. 1st Annual National Conf. on Artif. Intel., 1. The main reason for using (0, 2) is to facilitate the use of an pp. 15–17. Bryant, R. and Griffiths, P. 1986. Reduction for constrained varia- intermediate point (index 1). κ2 tional problems and ds. American Journal of Mathematics, 2. The notation (x0, y0,θ0) denotes that the interpolation passes 2 108:525–570. through (x0, y0) at tangent angle θ0. 3. According to Knuth, prior attempts at laying a scientific foun- Cesaro, E. 1886. Les lignes barycentriques. Nouvelles annales de dation for calligraphy and mathematical typography, e.g., those mathematiques, 3(5):511–520. of Feliciano (1460), Pacivoli (1509), Torriello (1517), Palatino Cornu, A. 1874. Methode nouvelle pour la discussion des probl`emes (1574), Tory (1579) and Maxon (1676), relied on “rigid ruler de diffraction. Journal physique theorique´ et appliquee´ . and compass” methods and, were aesthetic failures, “deprived of Dhandapani, R. and Kimia, B.B. Role of scale in partitioning shape. calligraphic grace”. In Proceedings of the IEEE International Conference on Image 4. It is curious that, in actual applications of this curve completion Processing, Rochester, New York, IEEE Computer Society Press solution, the resulting curve does not, unlike Renaissance geome- (Accepted). ters, describe the boundary of a symbol; rather, it describes the Euler, L. 1744. Methodus inveniendi lineas curvas maximi minimive “central curve” of the symbol and, as such, allows the shape of proprietate gaudentes. Lausanne. the pen to vary. This is precisely a description of shape as the ge- Euler’s integrals and Euler’s spiral. 1918. American Math Monthly, ometry of the medial axis curve as well as the radial or dynamic Vol. 25(8). changes as a point moves along this axis (Knuth, 1979). Farin, G.E. 1996. Curves and Surfaces for Computer-Aided Geomet- 5. It should also be noted that Grossberg and Mingolla (1985) pro- ric Design: A Practical Guide (Computer Science and Scientific pose a cooperative-competitive framework consisting of itera- Computing Series), 4th ed. Academic Press. tive nonlinear convolutions to complete illusory contours, among Grossberg, S. and Mingolla, E. 1985. Neural dynamics of other tasks. form perception: Boundary completion, illusory figures, and 6. The curvature of an elastic curve meeting these end conditions neon color spreading. Psychological Review, 92(2):173– (but with free length) satisfies (Birkhoff and Boor, 1965) 211. Guy, G. and Medioni, G. Perceptual grouping using global saliency- 1 3 κss + κ = 0. enhancing operators. In International Conference on Pattern 2 Recognition, The Hague, Netherlands, August 30–September 3, 7. If we posit κ0 and L as the free parameters, γ can be eliminated 1992. Computer Society Press, pp. I:99–103. θ −θ −κ by γ = 2 ( 1 0) 0 L , in Eq. (3), leading to two equations and two Herault, L. and Horaud, R. 1993. Figure-ground discrimination: A L2 unknowns. However, numerical experience with these geometric combinatorial approach. PAMI, 15(9):899–914. interpolants shows that another set of free parameters, namely, Higgins, A. 1921. The Transition Spiral and its Introduction to Rail- κ0 and κ2 (initial and final curvatures), is better suited to the way Curves. Constable, London. recovery of the Euler spiral. In other words, we use an alternate, Hoffman, D.D. and Richards, W.A. 1985. Parts of recognition. Cog- more symmetric, yet equivalent, description of each Euler Spiral nition, 18:65–96. segment in terms (x0, y0,θ0) and (κ0,κ2,γ) Horn, B.K.P. 1983. The curve of least energy. ACM Trans. Math. 8. We use subscript two to allow for the intermediate point Softw., 9(4):442–460. (x1, y1,θ1) which joins two biarcs. Johannes, M.S., Sebastian, T.B., Tek, H., and Kimia, B.B. 2001. 9. It is instructive to consider the limiting case of the second solution Perceptual organization as object recognition divided by two. In as θ2 → θ0; let θ2 = θ0 + where is a small number. The second Workshopon Perceptual Organization in Computer Vision, pp. 41– solution implies very small and close curvatures, corresponding 46. to a biarc consisting of very large circles. In the limit, the biarc Kanizsa, G. 1979. Organization in Vision: Essays on Gestalt Percep- consists of two infinite length line segments joining at infinity. tion. Praeger. Note also that by taking arbitrarily small, the second solution Knuth, D.E. 1979. Mathematical typography. Bulletin (new series) can be made to have smaller |κ2 − κ1| but at the expense of arbi- of the American mathematical Society, 1(2):337–372. trarily enlarging its length. Since the Euler spiral corresponding Kurtz, C. 1945. Track and Turnout Engineering. Simmons- to one extreme biarc may be “better” than another, even when the Boardman Publishing Corporation, New York. corresponding biarcs hold the opposite relationship, we consider Leonard, I. 1988. More on Fresnel integrals. American Mathematical both extremal solution to generate the Euler spiral. Monthly, 95:431–433. 182 Kimia, Frankel and Popescu

Love, A. 1927. A Treatise on the Mathematical Theory of Elasticity, Siddiqi, K. and Kimia, B.B. 1995. Parts of visual form: Computa- 4th ed. Cambridge University Press, Cambridge. tional aspects. PAMI, 17(3):239–251. Mumford, D. 1994. Elastica and computer vision. In Algebraic Ge- Sokolnikoff, J. 1956. Mathematical Theory of Elasticity. New York. ometry and Its Applications, Springer-Verlag, pp. 491–506. Spanier, J. and Oldham, K. 1987. An Atlas of Functions. Hemisphere, Nitzberg, M., Mumford, D., and Shiota, T. 1993. Filtering, Segmen- Washington, DC. tation and Depth. Springer-Verlag. Talbot, A.N. 1927. The Railway Transition Spiral, 6th ed. McGraw- Onn, R. and Bruckstein, A. 1990. Integrability disambiguates surface Hill Book Company, Inc., New York and London. recovery in two-image photometric stereo. International Journal Ullman, S. 1976. Filling-in the gaps: The shape of subjective contours of Computer Vision, 5:1:105–113. and a model for their generation, 25:1–6. Parent, P. and Zucker, S.W. 1989. Trace inference, curvature consis- Weiss, I. 1988. 3D shape representation by contours. Computer Vi- tency and curve detection. PAMI, 11(8):823–839. sion, Graphics, and Image Processing, 41:80–100. Press, W., Flannery, B., Teukolsky, S., and Vetterling, W. 1993. Nu- Weisstein, E.W. 1998. French curve. www.astro.virginia.edu/ merical Recipes in C: The Art of Scientific Computing, 2nd ed., ˜eww6n/math/FrenchCurve.html. Fresnel Integrals, Cosine and Sine Integrals. Cambridge Univer- Williams, L. and Jacobs, D. 1997. Local parallel computation sity Press, Cambridge, England. of stochastic completion fields. Neural Computation, 9(4):837– Rutkowski, W.S. 1979. Shape completion. and 858. Image Processing, 9:89–101. Williams, L. and Thornber, K. 1998. A comparison of measures Sarkar, S. and Boyer, K. 1992. Perceptual organization using for detecting natural shapes in cluttered backgrounds. ECCV98, Bayesian networks. In CVPR92, pp. 251–256. 1407(2):432–448. Sha’ashua, A. and Ullman, S. 1988. Structural saliency: The de- Williams, L. and Thornber, K. 1999. A comparison of measures tection of globally salient structures using a locally connected for detecting natural shapes in cluttered backgrounds. IJCV, network. In Second International Conference on Computer Vi- 34(2/3):81–96. sion (Tampa,, FL, December 5–8, 1988), Washington, DC, IEEE Williams, L.R. and Jacobs, D.W. 1995. Stochastic completion fields: Computer Society Press. A neural model of illusory contour shape and salience. In Proceed- Sharon, E., Brandt, A., and Basri, R. Completion energies and scale. ings of the Fifth International Conference on Computer Vision, IEEE Transactions on Pattern Analysis and Machine Intelligence Boston, Massachusetts, IEEE Computer Society Press, pp. 408– 22(10):1117–1131, October 2000. 415.