Class AffineMapping2D

All Implemented Interfaces:
Inversion, Jacobian, Mapping2D, Cloneable
Direct Known Subclasses:
Rotation2D, Scaling2D, Shear2D, Translation2D

This class represents an affine transformation in 2D, which can be defined by three pairs of corresponding points. It can be assumed that every instance of this class is indeed an affine mapping. Instances are immutable. See Secs. 21.1.3 and 21.3.1 of [1] for details.

[1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).

  • Constructor Details

    • AffineMapping2D

      public AffineMapping2D()
      Creates the identity mapping.
    • AffineMapping2D

      public AffineMapping2D(double[][] A)
      Creates a linear mapping from a transformation matrix A, which must be at least of size 2 x 3. The elements of A are copied into a 3x3 identity matrix. If A is larger than 2 x 3, the remaining elements are ignored.
      Parameters:
      A - a 2x3 (or larger) matrix
    • AffineMapping2D

      public AffineMapping2D(double a00, double a01, double a02, double a10, double a11, double a12)
      Creates an affine mapping from the specified matrix elements.
      Parameters:
      a00 - matrix element A_00
      a01 - matrix element A_01
      a02 - matrix element A_02
      a10 - matrix element A_10
      a11 - matrix element A_11
      a12 - matrix element A_12
    • AffineMapping2D

      Creates a new affine mapping from an existing affine mapping.
      Parameters:
      m - an affine mapping
  • Method Details

    • fromPoints

      public static AffineMapping2D fromPoints(Pnt2d[] P, Pnt2d[] Q)
      Creates an affine 2D mapping from two sequences of corresponding points. If 3 point pairs are specified, the mapping is exact, otherwise a minimum least-squares fit is calculated.
      Parameters:
      P - the source points
      Q - the target points
      Returns:
      a new AffineMapping2D instance for the two point sets
    • fromPoints

      public static AffineMapping2D fromPoints(Pnt2d p0, Pnt2d p1, Pnt2d p2, Pnt2d q0, Pnt2d q1, Pnt2d q2)

      Creates an affine mapping from 3 pairs of corresponding 2D points (p0, p1, p2) → (q0, q1, q2). The solution is found in closed form (see [1], Sec. 21.1.3, eq. 21.31).

      [1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).

      Parameters:
      p0 - point 1 of source triangle A
      p1 - point 2 of source triangle A
      p2 - point 3 of source triangle A
      q0 - point 1 of source triangle B
      q1 - point 2 of source triangle B
      q2 - point 3 of source triangle B
      Returns:
      a new AffineMapping2D instance
    • isAffine

      public static boolean isAffine(LinearMapping2D map)
      Checks if the given linear mapping could be affine, i.e. if the bottom row of its transformation matrix is (0, 0, 1). Note that this is a necessary but not sufficient requirement. The threshold Arithmetic.EPSILON_DOUBLE is used in this check.
      Parameters:
      map - a linear mapping
      Returns:
      true if the mapping could be affine
    • concat

      Concatenates this mapping A with another affine mapping B and returns a new mapping C, such that C(x) = B(A(x)).
      Parameters:
      B - the second mapping
      Returns:
      the concatenated affine mapping
    • applyTo

      public Pnt2d applyTo(Pnt2d pnt)
      Description copied from interface: Mapping2D
      Applies this mapping to a single 2D point.
      Specified by:
      applyTo in interface Mapping2D
      Overrides:
      applyTo in class LinearMapping2D
      Parameters:
      pnt - the original point
      Returns:
      the transformed point
    • getInverse

      Calculates and returns the inverse mapping. Note that the inverse A' of a projective transformation matrix A is again a linear transformation but its a'2' element is generally not 1. Scaling A' to A'' = A' / a22' yields a projective transformation that reverses A. While A * A' = I, the result of A * A'' is a scaled identity matrix. Note that inverting an affine transformation always yields another affine transformation.
      Specified by:
      getInverse in interface Inversion
      Overrides:
      getInverse in class ProjectiveMapping2D
      Returns:
      the inverse projective transformation
    • duplicate

      Returns a copy of this mapping.
      Overrides:
      duplicate in class ProjectiveMapping2D
      Returns:
      a new affine mapping
    • getJacobian

      public double[][] getJacobian(Pnt2d xy)
      Description copied from interface: Jacobian

      Returns the Jacobian matrix for this mapping, evaluated at the given 2D point. See Appendix Sec. D.1.1 of [1] for more details.

      [1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).

      Specified by:
      getJacobian in interface Jacobian
      Overrides:
      getJacobian in class ProjectiveMapping2D
      Parameters:
      xy - the 2D position to calculate the Jacobian for
      Returns:
      the Jacobian matrix