Class ProjectiveMapping2D

java.lang.Object
imagingbook.common.geometry.mappings.linear.LinearMapping2D
imagingbook.common.geometry.mappings.linear.ProjectiveMapping2D
All Implemented Interfaces:
Inversion, Jacobian, Mapping2D, Cloneable
Direct Known Subclasses:
AffineMapping2D

public class ProjectiveMapping2D extends LinearMapping2D implements Jacobian

This class represents a projective transformation in 2D (also known as a "homography"). It can be specified uniquely by four pairs of corresponding points. It can be assumed that every instance of this class is indeed a projective mapping. See Secs. 21.1.4 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

    • ProjectiveMapping2D

      Creates the identity mapping.
    • ProjectiveMapping2D

      public ProjectiveMapping2D(double[][] A)
      Creates a projective mapping from a transformation matrix A, of arbitrary size. All relevant elements of A are inserted into actual 3x3 transformation matrix, except element (2,2) which is ignored and always set to 1 (to keep the transformation projective). If A is larger than 3 x 3, the remaining elements are ignored.
      Parameters:
      A - a transformation matrix of arbitrary size
    • ProjectiveMapping2D

      public ProjectiveMapping2D(double a00, double a01, double a02, double a10, double a11, double a12, double a20, double a21)
      Creates a projective 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
      a20 - matrix element A_20
      a21 - matrix element A_21
    • ProjectiveMapping2D

      Creates a projective mapping from any linear mapping. The transformation matrix gets normalized to a22 = 1.
      Parameters:
      m - a linear mapping
    • ProjectiveMapping2D

      Creates a projective mapping from an existing instance.
      Parameters:
      m - a projective mapping
  • Method Details

    • fromPoints

      public static ProjectiveMapping2D fromPoints(Pnt2d[] P, Pnt2d[] Q)
      Creates a projective 2D mapping from two sequences of corresponding points. If 4 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 projective mapping for the two point sets
    • concat

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

      Returns a copy of this mapping.
      Overrides:
      duplicate in class LinearMapping2D
      Returns:
      a new projective mapping
    • 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.
      Specified by:
      getInverse in interface Inversion
      Overrides:
      getInverse in class LinearMapping2D
      Returns:
      the inverse projective transformation
    • 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
      Parameters:
      xy - the 2D position to calculate the Jacobian for
      Returns:
      the Jacobian matrix
    • main

      public static void main(String[] args)
      For testing only.
      Parameters:
      args - ignored