Python implementation of "Elliptic Fourier Features of a Closed Contour"
An Python/NumPy implementation of a method for approximating a contour with a Fourier series, as described in .
pip install pyefd
General usage examples
This section describes the general usage patterns of
from pyefd import elliptic_fourier_descriptors coeffs = elliptic_fourier_descriptors(contour, order=10)
The coefficients returned are the
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)
If you are using OpenCV to generate contours, this example shows how to
connect it to
import cv2 import numpy from pyefd import elliptic_fourier_descriptors # Find the contours of a binary image using OpenCV. contours, hierarchy = cv2.findContours( im, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # Iterate through all contours found and store each contour's # elliptical Fourier descriptor's coefficients. coeffs =  for cnt in contours: # Find the coefficients of all contours coeffs.append(elliptic_fourier_descriptors( numpy.squeeze(cnt), order=10))
Using EFD as features
To use these as features, one can write a small wrapper function:
from pyefd import elliptic_fourier_descriptors 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  for more technical details.
Run tests with with Pytest:
The tests include a single image from the MNIST dataset of handwritten digits () as a contour to use for testing.
: Frank P Kuhl, Charles R Giardina, Elliptic Fourier features of a closed contour, Computer Graphics and Image Processing, Volume 18, Issue 3, 1982, Pages 236-258, ISSN 0146-664X, http://dx.doi.org/10.1016/0146-664X(82)90034-X.
All notable changes to this project will be documented in this file.
- Added a demo for 3D surfaces with cylindrical symmetries. (
- Fixes incorrectly plotted curves when no
imshowhas been called.
- Fixes ugly coefficient calculation code.
elliptic_fourier_descriptorsmethod. Merged #11. Fixes #5.
- Documentation correction. Merged #12.
- Deleted broken example script
- Change CI from Azure Devops to Github Actions
- Merged PR #4: Vectorized contour reconstruction function
- Merged PR #2: Numpy vectorized efd
- Moved from Travis CI to Azure Pipelines
- Replaced rst with markdown
- Updated setup.py
- Updated numpy requirement
- Added Pipfile
- Ran Black on code
- Testing on 3.6
- New example for OpenCV
- Updated documentation
- Deemed stable enough for version 1.0 release
- Created documentation.
- Testing with pytest instead of nosetests.
- Added Coveralls use.
- Fixed MANIFEST
- Added LICENSE file that was missing.
- Initial release
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for pyefd-1.6.0-py2.py3-none-any.whl