Package: pyefd
PyEFDAn Python/NumPy implementation of a method for approximating a contour with a Fourier series, as described in [1].InstallationpipinstallpyefdUsageGiven a closed contour of a shape, generated by e.g.scikit-imageorOpenCV, this package can fit aFourier seriesapproximating the shape of the contour.General usage examplesThis section describes the general usage patterns ofpyefd.frompyefdimportelliptic_fourier_descriptorscoeffs=elliptic_fourier_descriptors(contour,order=10)The coefficients returned are thea_n,b_n,c_nandd_nof 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:frompyefdimportelliptic_fourier_descriptorscoeffs=elliptic_fourier_descriptors(contour,order=10,normalize=False)Normalization can also be done afterwards:frompyefdimportnormalize_efdcoeffs=normalize_efd(coeffs)OpenCV exampleIf you are usingOpenCVto generate contours, this example shows how to
connect it topyefd.importcv2importnumpyfrompyefdimportelliptic_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=[]forcntincontours:# Find the coefficients of all contourscoeffs.append(elliptic_fourier_descriptors(numpy.squeeze(cnt),order=10))Using EFD as featuresTo use these as features, one can write a small wrapper function:frompyefdimportelliptic_fourier_descriptorsdefefd_feature(contour):coeffs=elliptic_fourier_descriptors(contour,order=10,normalize=True)returncoeffs.flatten()[3:]If the coefficients are normalized, thencoeffs[0, 0] = 1.0,coeffs[0, 1] = 0.0andcoeffs[0, 2] = 0.0, so they can be disregarded when using the elliptic Fourier descriptors as features.See [1] for more technical details.TestingRun tests with withPytest:py.testtests.pyThe tests include a single image from the MNIST dataset of handwritten digits ([2]) as a contour to use for testing.DocumentationSeeReadTheDocs.References[1]: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.[2]:LeCun et al. (1999): The MNIST Dataset Of Handwritten DigitsChangelogAll notable changes to this project will be documented in this file.The format is based onKeep a Changelog,
and this project adheres toSemantic Versioning.1.6.0(2021-12-09)AddedAdded a demo for 3D surfaces with cylindrical symmetries. (examples/example1.py)FixesFixes incorrectly plotted curves when noimshowhas been called.Fixes ugly coefficient calculation code.1.5.1(2021-01-22)Addedreturn_transformationkeyword onelliptic_fourier_descriptorsmethod. Merged #11. Fixes #5.FixesDocumentation correction. Merged #12.RemovedDeleted broken example scriptscikit_image.py.1.4.1(2020-09-28)AddedAddedCHANGELOG.mdChangedChange CI from Azure Devops to Github Actions1.4.0(2019-07-27)ChangedMerged PR #4: Vectorized contour reconstruction function1.3.0(2019-06-18)ChangedMerged PR #2: Numpy vectorized efdMoved from Travis CI to Azure PipelinesReplaced rst with markdown1.2.0(2018-06-14)ChangedUpdated setup.pyUpdated numpy requirementAddedAdded PipfileRan Black on codeTesting on 3.61.1.0(2018-06-13)AddedNew example for OpenCVUpdated documentation1.0.0(2016-04-19)ChangedDeemed stable enough for version 1.0 releaseAddedCreated documentation.0.1.2(2016-02-29)ChangedTesting with pytest instead of nosetests.AddedAdded Coveralls use.0.1.1(2016-02-17)FixedFixed MANIFESTAddedAdded LICENSE file that was missing.0.1.0 (2016-02-09)AddedInitial release