Skip to main content

Python implementation of "Elliptic Fourier Features of a Closed Contour"

Project description

PyEFD

https://travis-ci.org/hbldh/pyefd.svg?branch=master Documentation Status http://img.shields.io/pypi/v/pyefd.svg http://img.shields.io/pypi/dm/pyefd.svg http://img.shields.io/pypi/l/pyefd.svg https://coveralls.io/repos/github/hbldh/pyefd/badge.svg?branch=master

An Python/NumPy implementation of a method for approximating a contour with a Fourier series, as described in [1].

Installation

$ pip install pyefd

Usage

Given a closed contour of a shape, generated by e.g. scikit-image or OpenCV, this package can fit a Fourier series approximating the shape of the contour:

from pyefd import elliptic_fourier_descriptors
coeffs = elliptic_fourier_descriptors(contour, order=10)

The coefficients returned are the a_n, b_n, c_n and d_n of the following Fourier series representation of the shape.

The coefficients returned are by default normalized so that they are rotation and size-invariant. This can be overridden by calling:

from pyefd import elliptic_fourier_descriptors
coeffs = elliptic_fourier_descriptors(contour, order=10, normalize=False)

Normalization can also be done afterwards:

from pyefd import normalize_efd
coeffs = normalize_efd(coeffs)

To use these as features, one can write a small wrapper function:

def efd_feature(contour):
    coeffs = elliptic_fourier_descriptors(contour, order=10, normalize=True)
    return coeffs.flatten()[3:]

If the coefficients are normalized, then coeffs[0, 0] = 1.0, coeffs[0, 1] = 0.0 and coeffs[0, 2] = 0.0, so they can be disregarded when using the elliptic Fourier descriptors as features.

See [1] for more technical details.

Testing

Run tests with:

$ python setup.py test

or with Pytest:

$ py.test tests.py

The tests includes a single image from the MNIST dataset of handwritten digits ([2]) as a contour to use for testing.

Documentation

See ReadTheDocs.

References

v1.0 (2016-04-19)

  • Deemed stable enough for version 1.0 release

  • Created documentation.

v0.1.2 (2016-02-29)

  • Testing with pytest instead of nosetests.

  • Added Coveralls use.

v0.1.1 (2016-02-17)

  • Fixed MANIFEST

  • Added LICENSE file that was missing.

v0.1.0 (2016-02-09)

  • Initial release

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

pyefd-1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyefd-1.0-py2.py3-none-any.whl (7.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pyefd-1.0.tar.gz.

File metadata

  • Download URL: pyefd-1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyefd-1.0.tar.gz
Algorithm Hash digest
SHA256 4f5cd7b4ad8f1df72ad3178db791904eed4b2ba65d85448ee38d91fd871c2fef
MD5 06f0faf538ecf7d7d58e809fe37dcb3c
BLAKE2b-256 16f7c7e623049bbaa974fbf72fc46f92b459de41b1421550cfe2aad827fd450d

See more details on using hashes here.

File details

Details for the file pyefd-1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pyefd-1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c39ed5e58bdb2d2fee591650eb2b0d7772ca4df45e9b039b6953330f6f98d224
MD5 30ea74f4b98673a769c4715accf94e0a
BLAKE2b-256 47c03f1fc1bbdbb165863071a327ba14b4f033f7c9ab0735e5c055c57988c6c4

See more details on using hashes here.

Supported by

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