{"id":17272485,"url":"https://github.com/hbldh/pyefd","last_synced_at":"2025-08-19T22:32:15.304Z","repository":{"id":45537636,"uuid":"51270640","full_name":"hbldh/pyefd","owner":"hbldh","description":"Python implementation of \"Elliptic Fourier Features of a Closed Contour\"","archived":false,"fork":false,"pushed_at":"2023-08-28T12:33:23.000Z","size":256,"stargazers_count":86,"open_issues_count":3,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-09T19:53:34.224Z","etag":null,"topics":["contours","feature-extraction","features","fourier-series","numpy","python"],"latest_commit_sha":null,"homepage":"http://pyefd.readthedocs.org/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hbldh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-02-07T22:59:34.000Z","updated_at":"2024-11-28T12:41:58.000Z","dependencies_parsed_at":"2022-09-22T06:11:33.702Z","dependency_job_id":"f62ccedd-191b-41f0-ac13-3d8aec5653f7","html_url":"https://github.com/hbldh/pyefd","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hbldh%2Fpyefd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hbldh%2Fpyefd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hbldh%2Fpyefd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hbldh%2Fpyefd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hbldh","download_url":"https://codeload.github.com/hbldh/pyefd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230374118,"owners_count":18216041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["contours","feature-extraction","features","fourier-series","numpy","python"],"created_at":"2024-10-15T08:48:45.975Z","updated_at":"2024-12-19T04:06:55.805Z","avatar_url":"https://github.com/hbldh.png","language":"Python","readme":"PyEFD\n=====\n\n[![Build and Test](https://github.com/hbldh/pyefd/workflows/Build%20and%20Test/badge.svg)](https://github.com/hbldh/pyefd/actions?query=workflow%3A%22Build+and+Test%22)\n[![Documentation Status](https://readthedocs.org/projects/pyefd/badge/?version=latest)](http://pyefd.readthedocs.org/en/latest/?badge=latest)\n[![image](http://img.shields.io/pypi/v/pyefd.svg)](https://pypi.python.org/pypi/pyefd/)\n[![image](http://img.shields.io/pypi/l/pyefd.svg)](https://pypi.python.org/pypi/pyefd/)\n[![image](https://coveralls.io/repos/github/hbldh/pyefd/badge.svg?branch=master)](https://coveralls.io/github/hbldh/pyefd?branch=master)\n\nAn Python/NumPy implementation of a method for approximating a contour with a Fourier series, as described in [1].\n\nInstallation\n------------\n\n```bash\npip install pyefd\n```\n\nUsage\n-----\n\nGiven a closed contour of a shape, generated by e.g. [scikit-image](http://scikit-image.org/) or\n [OpenCV](http://opencv.org/), this package can fit a \n [Fourier series](https://en.wikipedia.org/wiki/Fourier_series) approximating the shape of the contour.\n\n### General usage examples\n\nThis section describes the general usage patterns of `pyefd`.\n\n```python\nfrom pyefd import elliptic_fourier_descriptors\ncoeffs = elliptic_fourier_descriptors(contour, order=10)\n```\n\nThe coefficients returned are the `a_n`, `b_n`, `c_n` and `d_n` of the following Fourier series \nrepresentation of the shape.\n\nThe coefficients returned are by default normalized so that they are rotation and size-invariant. \nThis can be overridden by calling:\n\n```python\nfrom pyefd import elliptic_fourier_descriptors\ncoeffs = elliptic_fourier_descriptors(contour, order=10, normalize=False)\n```\n\nNormalization can also be done afterwards:\n\n```python\nfrom pyefd import normalize_efd\ncoeffs = normalize_efd(coeffs)\n```\n\n### OpenCV example\n\nIf you are using [OpenCV](http://opencv.org/) to generate contours, this example shows how to \nconnect it to `pyefd`.\n\n```python\nimport cv2 \nimport numpy\nfrom pyefd import elliptic_fourier_descriptors\n\n# Find the contours of a binary image using OpenCV.\ncontours, hierarchy = cv2.findContours(\n    im, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)\n\n# Iterate through all contours found and store each contour's \n# elliptical Fourier descriptor's coefficients.\ncoeffs = []\nfor cnt in contours:\n    # Find the coefficients of all contours\n    coeffs.append(elliptic_fourier_descriptors(\n        numpy.squeeze(cnt), order=10))\n```\n\n### Using EFD as features\n\nTo use these as features, one can write a small wrapper function:\n\n```python\nfrom pyefd import elliptic_fourier_descriptors\n\ndef efd_feature(contour):\n    coeffs = elliptic_fourier_descriptors(contour, order=10, normalize=True)\n    return coeffs.flatten()[3:]\n```\n\nIf the coefficients are normalized, then `coeffs[0, 0] = 1.0`, `coeffs[0, 1] = 0.0` and \n`coeffs[0, 2] = 0.0`, so they can be disregarded when using the elliptic Fourier descriptors as features.\n\nSee [1] for more technical details.\n\nTesting\n-------\n\nRun tests with with [Pytest](http://pytest.org/latest/):\n\n```bash\npy.test tests.py\n```\n\nThe tests include a single image from the MNIST dataset of handwritten digits ([2]) as a contour to use for testing.\n\nDocumentation\n-------------\n\nSee [ReadTheDocs](http://pyefd.readthedocs.org/).\n\nReferences\n----------\n\n[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, \u003chttp://dx.doi.org/10.1016/0146-664X(82)90034-X\u003e.](http://www.sci.utah.edu/~gerig/CS7960-S2010/handouts/Kuhl-Giardina-CGIP1982.pdf)\n\n[2]: [LeCun et al. (1999): The MNIST Dataset Of Handwritten Digits](http://yann.lecun.com/exdb/mnist/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhbldh%2Fpyefd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhbldh%2Fpyefd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhbldh%2Fpyefd/lists"}