Fitting Conics¶
Algebraic Fitting¶
- conics.fitting.fit_dlt(pts)[source]¶
Fits an arbitrary conic using direct linear transform (DLT) [HZ04] to the specified 2-D coordinates given by pts.
The resulting conic is not guaranteed to be of any specific type.
- Parameters:
pts (numpy.ndarray) – A set of 2-D coordinates to fit the conic to.
- Returns:
The estimated conic.
- Return type:
- conics.fitting.fit_nievergelt(pts, type='parabola', scale=False)[source]¶
Linear least-squares of specific type conics.
The method implements the approach proposed in [Nie04].
- Parameters:
pts (numpy.ndarray) – 2-D array of coordinates to fit the conic to.
type (str, None) – The desired conic type. None if no specific conic type is desired, or ellipse, parabola, or hyperbola.
scale (bool) – Scale points to unit standard deviation along each axis. Scaling generally improves the numerical robustness of the fit [HOLearyZM04]. The original method does not scale the points.
Geometric Fitting¶
Geometric fitting of conics involves minimizing some sort of orthogonal distances between the observed points and the points on the conic. This is in stark contrast to algebraic fitting which generally minimizes the quadratic curve representation of conics, which can be done linearly. Geometric fitting, however, generally requires solving a system of non-linear equations.
Solving a system of non-linear equations is typically done iteratively by
minimizing a cost function assumed to be convex. The latter requires an initial
guess of the solution which is reasonably close to the global optimum. In
practice, one can employ algebraic fit to estimate the initial set of the conic
parameters and then refine solution using non-linearly. An example of a such
approach is implemented by conics.Parabola.refine() and illustrated in
the following example.
(Source code, png, hires.png, pdf)
Geometrically fitted parabola in general position.¶
Parabola to Quadratic Bézier Curve¶
A parabola can be exactly represented by a second-degree Bézier curve. Employing accurate and does not suffer from quantization errors that particularly can occur when computing isocurves.
Specifying a second-degree Bézier curve requires providing three control points which determine the curve. While the outer control points can be chosen to be arbitrarily placed on the curve, the central control point must be computed from the intersection of the parabola slopes at the outer control points.
- conics.fitting.parabola_to_bezier(parabola, start, end)[source]¶
Determines the control points of a quadratic Bezier curve that exactly represents given parabola.
- Parameters:
parabola (conics.Parabola) – A parabola whose Bezier control points should be determined.
start (numpy.ndarray) – Starting 2-D coordinate on or around the curve from which the first control point is determined. The coordinate does not need to be lying exactly on the parabola. The method uses the coordinate to determine the shortest (orthogonal) distance contact point using
conics.Parabola.contact().end (numpy.ndarray) – Similar to the start parameter, denotes the outer point from which the final control point is determined.
- Returns:
A \(2\times3\) matrix of whose columns denote the three control points of the Bezier curve.
- Return type:
- Raises:
ValueError – Thrown if the slopes on the outer contact points of the parabolic curve do not intersect. In this case, the parabola may be degenerate and correspond, e.g., to a straight line.
(Source code, png, hires.png, pdf)
The Importance of Normalization¶
Standardizing the 2-D coordinates to be mean-free with unit standard deviation may improve the numerical robustness of the fitting algorithm [CBvdHG03, HOLearyZM04].
(Source code, png, hires.png, pdf)
The effect of normalization on (algebraic) fit of a parabola.¶
In this example, the large range of the vertical axis dominates over the much smaller range of the horizontal axis. Without scaling, the algebraic fit therefore produces an elongated parabola that covers the predominant vertical axis. While this is a valid solution, it is perceptually inferior to the one estimated using normalized coordinates.
Constraining Conics¶
Sometimes, one wishes to refine an already fitted conic with respect to a set of
points to obtain a conic of specific type or with specific properties. For
instance, the conic obtained using direct linear transform (DLT) results in a
circle. However, one wants a parabola instead. Such constraint can be enforced
using conics.Conic.constrain().