Skip to main content

Lease squares fitting of Ellipses

Project description

DOI bdhammel

Least Squares fitting of ellipses, python routine

based on the publication Halir, R., Flusser, J.: 'Numerically Stable Direct Least Squares Fitting of Ellipses'

Install

pip install lsq-ellipse

https://pypi.org/project/lsq-ellipse/

Example execution

import numpy as np
from ellipse import LsqEllipse
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse

if __name__ == '__main__':
    # avalible in the `example.py` script in this repo
    X1, X2 = example.make_test_ellipse()

    X = np.array(list(zip(X1, X2)))
    reg = LsqEllipse().fit(X)
    center, width, height, phi = reg.as_parameters()

    print(f'center: {center[0]:.3f}, {center[1]:.3f}')
    print(f'width: {width:.3f}')
    print(f'height: {height:.3f}')
    print(f'phi: {phi:.3f}')

    fig = plt.figure(figsize=(6, 6))
    ax = plt.subplot()
    ax.axis('equal')
    ax.plot(X1, X2, 'ro', zorder=1)
    ellipse = Ellipse(
        xy=center, width=2*width, height=2*height, angle=np.rad2deg(phi),
        edgecolor='b', fc='None', lw=2, label='Fit', zorder=2
    )
    ax.add_patch(ellipse)

    plt.xlabel('$X_1$')
    plt.ylabel('$X_2$')

    plt.legend()
    plt.show()

ellipse fit

Cite this work

@software{ben_hammel_2020_3723294,
  author       = {Ben Hammel and Nick Sullivan-Molina},
  title        = {bdhammel/least-squares-ellipse-fitting: v2.0.0},
  month        = mar,
  year         = 2020,
  publisher    = {Zenodo},
  version      = {v2.0.0},
  doi          = {10.5281/zenodo.3723294},
  url          = {https://doi.org/10.5281/zenodo.3723294}
}

Ben Hammel, & Nick Sullivan-Molina. (2020, March 21). bdhammel/least-squares-ellipse-fitting: v2.0.0 (Version v2.0.0). Zenodo. http://doi.org/10.5281/zenodo.3723294

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lsq-ellipse-2.2.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

lsq_ellipse-2.2.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file lsq-ellipse-2.2.0.tar.gz.

File metadata

  • Download URL: lsq-ellipse-2.2.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for lsq-ellipse-2.2.0.tar.gz
Algorithm Hash digest
SHA256 2fbff816726e40acc5dc943919e7e1d54db94f891ee04baeb6b24416a0537324
MD5 47036eb783e8ce9c23014834f631d9de
BLAKE2b-256 1206a2bebc2ccbb9d57e7639541fcf70ba1d269b1168793413c7429aafc7ec24

See more details on using hashes here.

File details

Details for the file lsq_ellipse-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: lsq_ellipse-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for lsq_ellipse-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 efef5d9906cdb69cbf610245ca8c1d598300d9e6a493bb3a7355f160aaf27f55
MD5 67300f6538e6c3629896e7d79225cf43
BLAKE2b-256 0b1110d1875239d9258eac3524f08612cb5369bd53940c3e14cc5b7743a84621

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page