• No results found

Fitting ellipses and hyperbolas

2.2 Constrained fitting

2.2.2 Fitting ellipses and hyperbolas

Fitting ellipses and hyperbolas involves the quadratic constraint b2−4ac < 0 for ellipses and

g =£

a b c p q d ¤>.

Notice that since g is unique up to scaling by a scalar (d is the coefficient of the constant term), the constraint 4ac − b2= ±1 expresses both b2− 4ac < 0 (the discriminant condition for an ellipse) and b2− 4ac > 0 (the discriminant condition for hyperbolas) because it is up to us to choose a (negative or positive) scalar. Imposing the constraint 4ac − b2= ±1, one can avoid degenerate solutions and ensure that the estimated parameters indeed define an ellipse or hyperbola (depending on sign), invariant to rotations and translations [26]. Written in matrix notation, ellipse and hyperbola fitting require the constraint

q = g>diag     0 0 2 0 −1 0 2 0 0  , 03×3  g = g>Qg (2.29)

where q > 0 for fitting ellipses and q < 0 for fitting hyperbolas. (Evaluating g>Qg we get 4ac −

b2.) Using the matrix size reduction scheme from Section 2.2.1 we may write the constraint in the equivalent form

q1= g>1   0 0 2 0 −1 0 2 0 0  g1= g>1Q1g1. Seen as an optimization problem, we may then seek the solution to

min g1

g>1Sg1 s.t. g>1Q1g1= 1 where S is as defined in (2.28).

Introducing the Lagrange multiplier, we have min

g1,λ

g>1Sg1− λg>1Q1g1

whereλ ≥ 0. Differentiating w.r.t. the parameters we get a system of equations

2Sg1− 2λQ1g1 = 0 (2.30)

g>1Qg1 = 1

where we obtain g1as the solution to the generalized eigenvector problem

Sg1= λQ1g1. (2.31)

Supposeξ is a solution to the eigenvector problem, then so is κξ. We can choose κ to satisfy the constraint, hence

κ2ξ>Q 1ξ = 1 κ = s 1 ξ>Q 1ξ

and thus

ˆg1= κξ solves the system (2.30).

From the above it follows that for ellipse-specific fitting [26], the solution g1(and its ex- panded version g) corresponds ideally (in the absence of numerical errors) to the smallest positive eigenvalueλ of the eigenvalue problem (2.31) with the constraint g>1Q1g1= 1 (and its expanded form with the constraint g>Qg = 1), whereas for hyperbola-specific fitting [53], the best choice of g1(and its expanded version g) among the eigenvectors is found by back- substitution into (2.29).

Summarizing, the generalized eigenvalue problem (2.31) has three valid solutions with respect to the constraints: one elliptical and two hyperbolic solutions to the conic fitting problem, depending on the eigenvalueλ. There is a symmetry between only one of the hyperbolic solutions and the elliptical solution, which enables us to uniquely identify the correct solutions [53].

Lemma 1. Let A and B be symmetric square matrices, with A being positive definite. The signs

of the generalized eigenvalues of

Aξ = λBξ (2.32)

are the same as those of the matrix B, up to a permutation of the indices.

Proof. The proof is adopted from [55]. Let us define the spectrumσ(A) as the set of eigen-

values of A and letσ(A, B) be the set of eigenvalues of the matrix pair (A, B) in (2.32). Let the inertia i (B) be defined as the set of signs ofσ(B) and let i (A, B) be the inertia of σ(A, B). With these notations, we have to prove that i (A, B) = i (B). As A is positive definite, it may be decomposed as W2for symmetric W, allowing us to write (2.32) as

W2ξ = λBξ.

Substitutingϑ = Wξ and multiplying by W−1from the left, we get

ϑ = λW−1BW−1ϑ

so thatσ(A, B) = σ¡W−1BW−1¢ and thus i (A, B) = i ¡W−1BW−1¢. From Sylvester’s law of in- ertia [28], we have that for any symmetric A and nonsingular X, i (A) = i¡X>AX¢. Therefore, substituting X = X>= W−1we have i (B) = i¡W−1BW−1¢ = i (A, B).

Lemma 2. Let A and B be symmetric square matrices, with A being positive definite. Ifλkand the correspondingξkare a solution to the eigensystem

Aξ = λBξ

then the sign ofλkmatches the sign ofξ>kBξk.

Proof. The proof is adopted from [55]. Multiplying both sides of (2.32) withξ>k from the left we have

ξ>

kAξk= λξ>kBξ>k.

Since A is positive definite,ξ>kAξk> 0 and therefore λi and the scalarξ>kBξ>k must have the

Theorem 3. The solution of the conic fitting problem defined by the generalized eigensystem Sg = λQg

subject to the constraint matrix

Q =   0 0 −2 0 1 0 −2 0 0  

defining the constraint b2−4ac < 0 delivers three nontrivial solutions: one and only one ellip-

tical and two hyperbolic solutions.2

Proof. Since the (non-zero) eigenvalues of Q are −2, 1 and 2, from Lemma 1 we have that

there is one and only one negative eigenvalue and two positive eigenvalues, associated with the solutions gk. Since the equations are homogeneous, both the positive and negative

eigenvalues correspond to eigenvectors that are valid solutions. Then according to Lemma 2, there are two cases: (1) for a negative eigenvalue the constraint g>kQgk= b2−4ac is negative,

and gk is a set of coefficients representing an ellipse; (2) for positive eigenvalues, the con-

straint g>kQgk= b2− 4ac is positive, and gk is a set of coefficients representing a hyperbola;

there are two such solutions. From a geometric perspective, there are two hyperbolic so- lutions since the constraint only defines that two pairs of real asymptotes must exist. The solution can never produce a parabola, since this would require g>kQgk = 0, which is not

permitted by problem formulation.

Thus, there are two symmetric eigenvalues of the constraint matrixλk1= −2 and λk2= 2;

these correspond to the optimal elliptical and hyperbolic solutions, respectively. The third eigenvalueλk3 = 1 also represents a hyperbola, however, it does not minimize the error as

desired, but maximizes it. This means that the eigenvector gk1 associated with the negative

constraint coefficient

κk1= b

2

k1− 4ak1ck1

is the best elliptical fit, while the eigenvector gk2associated with the positive constraint co-

efficient

κk2= b

2

k2− 4ak2ck2

with the value nearest to that of the elliptical solutionκk1is the best hyperbolic fit.

Related documents