Crate efd[][src]

This crate implements Elliptical Fourier Descriptor (EFD) curve fitting by using ndarray to handle the 2D arrays.

Reference: Kuhl, FP and Giardina, CR (1982). Elliptic Fourier features of a closed contour. Computer graphics and image processing, 18(3), 236-258.

The following is an example. The contours are always Nx2 array in the functions.

use std::f64::consts::TAU;
use ndarray::{Array1, Axis, stack};
use efd::{efd_fitting, ElementWiseOpt};

fn main() {
    const N: usize = 10;
    let circle = stack!(Axis(1),
                        Array1::linspace(0., TAU, N).cos(),
                        Array1::linspace(0., TAU, N).sin());
    assert_eq!(circle.shape(), &[10, 2]);
    let new_curve = efd_fitting(&circle, 20, None);
    assert_eq!(new_curve.shape(), &[20, 2]);
}

Arrays have “owned” and “view” two data types, all functions are compatible.

Traits

ElementWiseOpt

Implement several element-wise operations for ndarrays.

Functions

calculate_efd

Compute the Elliptical Fourier Descriptors for a polygon.

efd_fitting

Curve fitting using Elliptical Fourier Descriptor.

fourier_power

Compute the total Fourier power and find the minimum number of harmonics required to exceed the threshold fraction of the total power.

inverse_transform

Perform an inverse fourier transform to convert the coefficients back into spatial coordinates.

locus

Compute the dc coefficients, used as the locus when calling inverse_transform.

normalize_efd

Normalize the Elliptical Fourier Descriptor coefficients for a polygon.

nyquist

Returns the maximum number of harmonics that can be computed for a given contour, the Nyquist Frequency.

rotate_contour

Rotates a contour about a point by a given amount expressed in degrees.