Class FourierDescriptor

java.lang.Object
imagingbook.common.geometry.fd.FourierDescriptor

public class FourierDescriptor extends Object

This class represents elliptic Fourier descriptors. See Ch. 26 of [1] for additional details including invariance calculations.

[1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction Using Java, 2nd ed, Springer (2016).

Version:
2022/10/24
See Also:
  • Field Details

  • Constructor Details

    • FourierDescriptor

      Constructor using the default scale (1.0).
      Parameters:
      G - a complex-valued DFT spectrum
    • FourierDescriptor

      public FourierDescriptor(Complex[] G, double scale)
      Constructor using a specific scale.
      Parameters:
      G - a complex-valued DFT spectrum
      scale - the reconstruction scale
    • FourierDescriptor

      Constructor for cloning Fourier descriptors.
      Parameters:
      fd - an existing instance
  • Method Details

    • size

      public int size()
      Returns the size (length) of this Fourier descriptor's array of DFT coefficients G. The resulting value is always odd.
      Returns:
      the size of the DFT coefficient array (M)
    • getScale

      public double getScale()
      Returns the scale of this Fourier descriptor, that is, the factor required to scale it to its original (sample) size. The scale factor is changed in the process of making descriptors scale-invariant.
      Returns:
      the scale factor
    • getMp

      public int getMp()
      Returns the number of Fourier coefficient pairs for this descriptor. The result is (M-1)/2, M being the size of the DFT coefficient array G.
      Returns:
      the number of Fourier coefficient pairs
    • getCoefficients

      Returns the array G = {G[0], ..., G[M-1]} of complex-valued DFT coefficients.
      Returns:
      the array of DFT coefficients
    • getCoefficient

      public Complex getCoefficient(int m)

      Returns the complex-valued DFT coefficient with the specified frequency index m. The returned coefficient is G[k] with k = (m mod G.length). Unique coefficients are returned for m = 0, ..., M-1, where M is the size of the DFT coefficient array, or m = -mp, ..., +mp where mp is the number of coefficient pairs. For example, given a Fourier descriptor with a 9-element spectrum,

       k    = 0 1 2 3 4 5 6 7 8
       G[k] = a b c d e f g h i 

      the following values are returned:

       getCoefficient(0)  → G[0] = a
       getCoefficient(1)  → G[1] = b
       ...
       getCoefficient(4)  → G[4] = e
       getCoefficient(-1) → G[8] = i
       ...
       getCoefficient(-4) → G[5] = f
       getCoefficient(-5) → G[4] = e
       ...
      Parameters:
      m - frequency index (positive or negative)
      Returns:
      the associated DFT coefficient
      See Also:
    • getCoefficientPair

      public Complex[] getCoefficientPair(int m)
      Returns the Fourier coefficient pair (G[-m], G[+m]) as a Complex valued array.
      Parameters:
      m - frequency index
      Returns:
      the DFT coefficient pair
    • getCoefficientIndex

      public int getCoefficientIndex(int m)
      Returns the coefficient array index for the specified frequency index, which may be positive or negative.
      Parameters:
      m - frequency index (positive or negative)
      Returns:
      the coefficient array index
      See Also:
    • makeInvariant

      Makes this Fourier descriptor invariant to scale, start-point and rotation. The descriptors center position (coefficient 0) is preserved. Performs the following normalization steps in sequence:

      1. scale invariance,
      2. start-point invariance,
      3. rotation invariance.

      Multiple candidate descriptors are returned, since start-point invariance is not unique. See Sec. 26.5 (Alg. 26.2) of [1] for additional details. The original (this) descriptor is not modified.

      [1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction Using Java, 2nd ed, Springer (2016).

      Returns:
      an array of modified Fourier descriptors
      See Also:
    • makeScaleInvariant

      Returns a new scale invariant Fourier descriptor by normalizing the L2 norm of the sub-vector {G[-mp], ..., G[-1], G[1], ..., G[mp]}. Coefficient G_0 remains unmodified. The new Fourier descriptor carries the associated scale (see getScale()). The original Fourier descriptor is not modified.
      Returns:
      a new scale-normalized Fourier descriptor
    • makeStartPointInvariant

      Returns a pair of start-point normalized Fourier descriptors. The original Fourier descriptor is not modified.
      Returns:
      a pair of start-point normalized Fourier descriptors
    • makeRotationInvariant

      Returns a new rotation invariant Fourier descriptor by applying complex rotation to all coefficients (except coefficient 0). The original Fourier descriptor is not modified.
      Returns:
      a new rotation-normalized Fourier descriptor
    • makeTranslationInvariant

      Returns a new translation invariant Fourier descriptor by setting coefficient 0 to zero. The original Fourier descriptor is not modified. This method is not used for shape invariance calculation, since position is not shape-relevant.
      Returns:
      a new translation-normalized Fourier descriptor
    • getShapeFull

      public Complex[] getShapeFull(int n)
      Reconstructs the associated 2D shape (closed contour) with N sample points, using all of the Fourier descriptor's coefficient pairs. The result is returned as an array of Complex values.
      Parameters:
      n - number of shape points
      Returns:
      reconstructed shape points
    • getShapePartial

      public Complex[] getShapePartial(int n, int p)
      Reconstructs the associated 2D shape (closed contour) with N sample points, using only a subset of the Fourier descriptor's coefficient pairs. The result is returned as an array of Complex values.
      Parameters:
      n - number of shape points
      p - the number of (low frequency) coefficient pairs to be used
      Returns:
      the reconstructed shape points
    • getShapePointFull

      public Complex getShapePointFull(double t)
      Reconstructs a single space point of the associated shape (closed contour) at the fractional path position t ∈ [0,1], using all of the Fourier descriptor's coefficient pairs.
      Parameters:
      t - path position
      Returns:
      the reconstructed shape point
    • getShapePointPartial

      public Complex getShapePointPartial(int p, double t)
      Reconstructs a single space point of the associated shape (closed contour) at the fractional path position t ∈ [0,1], using only a subset of the Fourier descriptor's coefficient pairs.
      Parameters:
      p - the number of (low frequency) coefficient pairs to be used
      t - path position ∈ [0,1]
      Returns:
      the reconstructed shape point
    • getShapePair

      public Complex[] getShapePair(int n, int m)
      Reconstructs the associated 2D shape (closed contour) with N sample points, using only a single coefficient pairs. The result is returned as an array of Complex values.
      Parameters:
      n - number of shape points
      m - the frequency index of the coefficient pair
      Returns:
      the reconstructed shape points
    • getShapePointPair

      public Complex getShapePointPair(int m, double t)
      Returns the spatial point reconstructed from a single DFT coefficient pair G[-m], G[+m] at position t ∈ [0,1]. Varying t creates points on an ellipse.
      Parameters:
      m - frequency index (coefficient pair number)
      t - contour position ∈ [0,1]
      Returns:
      reconstructed shape point
    • getEllipseParameters

      public double[] getEllipseParameters(int m)

      Returns the parameters of the geometric ellipse associated with a single Fourier coefficient pair (G[-m], G[+m]). See Sec. 26.3.5 of [1] for details. The result is in the form (ra, rb, xc, yc, theta).

      [1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction Using Java, 2nd ed, Springer (2016).

      Parameters:
      m - the frequency index of the Fourier coefficient pair
      Returns:
      the ellipse parameters (ra, rb, xc, yc, theta)
    • getEllipse

      public Shape getEllipse(int m)

      Returns the ellipse associated with a single Fourier coefficient pair (G[-m], G[+m]) as a (AWT) Shape object. The resulting ellipse is centered at (0,0). AffineTransform may be used to shift the ellipse to any other position.

      Parameters:
      m - the frequency index of the Fourier coefficient pair
      Returns:
      the ellipse (Shape)
      See Also:
    • distanceComplex

      public double distanceComplex(FourierDescriptor fd2)
      Returns a L2-type distance between this and another FourierDescriptor instance comparing the real and imaginary parts of all coefficient pairs. The zero-frequency coefficients are ignored.
      Parameters:
      fd2 - another Fourier descriptor
      Returns:
      the resulting distance
    • distanceComplex

      public double distanceComplex(FourierDescriptor fd2, int p)
      Returns a L2-type distance between this and another FourierDescriptor instance comparing the real and imaginary parts of a limited range of (low-frequency) coefficient pairs. The zero-frequency coefficients are ignored.
      Parameters:
      fd2 - another Fourier descriptor
      p - the number of (low-frequency) coefficient pairs to evaluate
      Returns:
      the resulting distance
    • distanceMagnitude

      public double distanceMagnitude(FourierDescriptor fd2)
      Returns a L2-type distance between this and another FourierDescriptor instance comparing the magnitudes of all coefficient pairs. The zero-frequency coefficients are ignored.
      Parameters:
      fd2 - another Fourier descriptor
      Returns:
      the resulting distance
    • distanceMagnitude

      public double distanceMagnitude(FourierDescriptor fd2, int p)
      Returns a L2-type distance between this and another FourierDescriptor instance comparing the magnitudes of a limited range of (low-frequency) coefficient pairs. The zero-frequency coefficients are ignored.
      Parameters:
      fd2 - another Fourier descriptor
      p - the number of (low-frequency) coefficient pairs to evaluate
      Returns:
      the resulting distance
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toPath

      public static Path2D toPath(Complex[] C)
    • toComplexArray

      public static Complex[] toComplexArray(Pnt2d[] points)