- 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).
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates the identity mapping.AffineMapping2D
(double[][] A) Creates a linear mapping from a transformation matrix A, which must be at least of size 2 x 3.AffineMapping2D
(double a00, double a01, double a02, double a10, double a11, double a12) Creates an affine mapping from the specified matrix elements.Creates a new affine mapping from an existing affine mapping. -
Method Summary
Modifier and TypeMethodDescriptionApplies this mapping to a single 2D point.Concatenates this mapping A with another affine mapping B and returns a new mapping C, such that C(x) = B(A(x)).Returns a copy of this mapping.static AffineMapping2D
fromPoints
(Pnt2d[] P, Pnt2d[] Q) Creates an affine 2D mapping from two sequences of corresponding points.static AffineMapping2D
Creates an affine mapping from 3 pairs of corresponding 2D points (p0, p1, p2) → (q0, q1, q2).Calculates and returns the inverse mapping.double[][]
getJacobian
(Pnt2d xy) Returns the Jacobian matrix for this mapping, evaluated at the given 2D point.static boolean
isAffine
(LinearMapping2D map) Checks if the given linear mapping could be affine, i.e.Methods inherited from class imagingbook.common.geometry.mappings.linear.ProjectiveMapping2D
concat, main
Methods inherited from class imagingbook.common.geometry.mappings.linear.LinearMapping2D
concat, concatenate, getTransformationMatrix, normalize, toString
-
Constructor Details
-
AffineMapping2D
public AffineMapping2D()Creates the identity mapping. -
AffineMapping2D
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
Creates an affine mapping from the specified matrix elements.- Parameters:
a00
- matrix element A_00a01
- matrix element A_01a02
- matrix element A_02a10
- matrix element A_10a11
- matrix element A_11a12
- matrix element A_12
-
AffineMapping2D
Creates a new affine mapping from an existing affine mapping.- Parameters:
m
- an affine mapping
-
-
Method Details
-
fromPoints
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 pointsQ
- 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 Ap1
- point 2 of source triangle Ap2
- point 3 of source triangle Aq0
- point 1 of source triangle Bq1
- point 2 of source triangle Bq2
- point 3 of source triangle B- Returns:
- a new
AffineMapping2D
instance
-
isAffine
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 thresholdArithmetic.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
Description copied from interface:Mapping2D
Applies this mapping to a single 2D point.- Specified by:
applyTo
in interfaceMapping2D
- Overrides:
applyTo
in classLinearMapping2D
- 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 interfaceInversion
- Overrides:
getInverse
in classProjectiveMapping2D
- Returns:
- the inverse projective transformation
-
duplicate
Returns a copy of this mapping.- Overrides:
duplicate
in classProjectiveMapping2D
- Returns:
- a new affine mapping
-
getJacobian
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 interfaceJacobian
- Overrides:
getJacobian
in classProjectiveMapping2D
- Parameters:
xy
- the 2D position to calculate the Jacobian for- Returns:
- the Jacobian matrix
-