{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / measure / fit / EllipseModel

class

skimage.measure.fit:EllipseModel

source: /dev/scikit-image/src/skimage/measure/fit.py :715

Signature

class   EllipseModel ( center axis_lengths theta )

Members

Summary

Total least squares estimator for 2D ellipses.

Extended Summary

The functional model of the ellipse is

xt = xc + a*cos(theta)*cos(t) - b*sin(theta)*sin(t)
yt = yc + a*sin(theta)*cos(t) + b*cos(theta)*sin(t)
d = sqrt((x - xt)**2 + (y - yt)**2)

where (xt, yt) is the closest point on the ellipse to (x, y). Thus d is the shortest distance from the point to the ellipse.

The estimator is based on a least squares minimization. The optimal solution is computed directly, no iterations are required. This leads to a simple, stable and robust fitting method.

Parameters

center : array_like of shape (2,)

Coordinates of ellipse center.

axis_lengths : array_like of shape (2,)

Length of first axis and length of second axis. Call these a and b.

theta : float

Angle of first axis.

Raises

: ValueError

If center does not have length 2.

Examples

em = EllipseModel((10, 15), (8, 4), np.deg2rad(30))
xy = em.predict_xy(np.linspace(0, 2 * np.pi, 25))
ellipse = EllipseModel.from_estimate(xy)
ellipse.center
ellipse.axis_lengths
round(ellipse.theta, 2)
np.round(abs(ellipse.residuals(xy)), 5)
The estimation can fail when — for example — all the input or output points are the same. If this happens, you will get an ellipse model for which ``bool(model)`` is ``False``:
if ellipse:
    print("Estimation succeeded.")
bad_data = np.ones((4, 2))
bad_ellipse = EllipseModel.from_estimate(bad_data)
if not bad_ellipse:
    print("Estimation failed.")
Trying to use this failed estimation transform result will give a suitable error:
bad_ellipse.residuals(xy)  # doctest: +IGNORE_EXCEPTION_DETAIL

Aliases

  • skimage.measure.EllipseModel