org.openimaj.math.geometry.transforms

## Class TransformUtilities

• ```public class TransformUtilities
extends Object```
A collection of static methods for creating transform matrices.
Author:
Sina Samangooei (ss@ecs.soton.ac.uk), Jonathon Hare (jsh2@ecs.soton.ac.uk)
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static Jama.Matrix` `affineMatrix(List<? extends IndependentPair<? extends Point2d,? extends Point2d>> data)`
Construct an affine transform using a least-squares fit of the provided point pairs.
`static Jama.Matrix` ```affineMatrixND(double[][] q, double[][] p)```
Find the affine transform between pairs of matching points in n-dimensional space.
`static Jama.Matrix` `affineMatrixND(List<? extends IndependentPair<? extends Coordinate,? extends Coordinate>> data)`
Find the affine transform between pairs of matching points in n-dimensional space.
`static Jama.Matrix` `approximateRotationMatrix(Jama.Matrix approx)`
Given an approximate rotation matrix Q (that doesn't necessarily conform properly to a rotation matrix), return the best estimate of a rotation matrix R such that the Frobenius norm is minimised: min||r-Q||^2_F.
`static Jama.Matrix` ```centeredRotationMatrix(double rot, int width, int height)```
Construct a rotation about the centre of the rectangle defined by width and height (i.e.
`static Jama.Matrix` `fundamentalMatrix8Pt(List<? extends IndependentPair<Point2d,Point2d>> data)`
The un-normalised 8-point algorithm for estimation of the Fundamental matrix.
`static Jama.Matrix` `fundamentalMatrix8PtNorm(List<? extends IndependentPair<Point2d,Point2d>> data)`
The normalised 8-point algorithm for estimating the Fundamental matrix
`static Pair<Jama.Matrix>` `getNormalisations(List<? extends IndependentPair<? extends Point2d,? extends Point2d>> data)`
Generates the data for normalisation of the points such that each matched point is centered about the origin and also scaled be be within Math.sqrt(2) of the origin.
`static Jama.Matrix` `homographyMatrix(List<? extends IndependentPair<? extends Point2d,? extends Point2d>> data)`
Compute the least-squares estimate (the normalised Direct Linear Transform approach) of the homography between a set of matching data points.
`static Jama.Matrix` `homographyMatrixNorm(List<? extends IndependentPair<? extends Point2d,? extends Point2d>> data)`
Compute the least-squares estimate (the normalised Direct Linear Transform approach) of the homography between a set of matching data points.
`static Jama.Matrix` `homographyToAffine(Jama.Matrix homography)`
Given a point x and y, calculate the 2x2 affine transform component of the 3x3 homography provided such that: H = AH_p H = { {h11,h12,h13}, {h21,h22,h23}, {h31,h32,h33} } H_p = { {1,0,0}, {0,1,0}, {h31,h32,1} } A = { {a11,a12,a13}, {a21,a22,a23}, {0,0,1} } so
`static Jama.Matrix` ```homographyToAffine(Jama.Matrix homography, double x, double y)```
Estimate the closest (in the least-squares sense) affine transform for a homography.
`static Jama.Matrix` ```makeTransform(Rectangle from, Rectangle to)```
Create a transform to transform from one rectangle to another.
`static IndependentPair<Point2d,Point2d>` ```normalise(IndependentPair<Point2d,Point2d> data, Pair<Jama.Matrix> normalisations)```
Normalise the data, returning a normalised copy.
`static List<? extends IndependentPair<Point2d,Point2d>>` ```normalise(List<? extends IndependentPair<Point2d,Point2d>> data, Pair<Jama.Matrix> normalisations)```
Normalise the data, returning a normalised copy.
`static Jama.Matrix` ```rigidMatrix(double[][] q, double[][] p)```
Compute the least-squares rigid alignment between two sets of matching points in N-dimensional space.
`static Jama.Matrix` `rigidMatrix(List<? extends IndependentPair<? extends Coordinate,? extends Coordinate>> data)`
Compute the least-squares rigid alignment between two sets of matching points in N-dimensional space.
`static Jama.Matrix` `rodrigues(double[] r)`
Convert a Rodrigues rotation vector to a rotation matrix.
`static double[]` `rodrigues(Jama.Matrix R)`
Convert a 3D rotation matrix to a Rodrigues rotation vector, which is oriented along the rotation axis, and has magnitude equal to the rotation angle.
`static Jama.Matrix` `rotationMatrix(double rot)`
Construct a rotation about 0, 0.
`static Jama.Matrix` ```rotationMatrixAboutPoint(double rot, float tx, float ty)```
Construct a rotation about the centre of the rectangle defined by width and height (i.e.
`static Jama.Matrix` ```scaleMatrix(double d, double e)```
Construct a homogeneous scaling transform with the given amounts of scaling.
`static Jama.Matrix` ```scaleMatrixAboutPoint(double sx, double sy, int tx, int ty)```
Create a scaling centered around a point.
`static Jama.Matrix` ```scaleMatrixAboutPoint(double sx, double sy, Point2d point)```
Create a scaling centered around a point.
`static Jama.Matrix` ```translateMatrix(double x, double y)```
Construct a translation.
`static Jama.Matrix` ```translateToPointMatrix(Point2d from, Point2d to)```
Given two points, get a transform matrix that takes points from point a to point b
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Method Detail

• #### rotationMatrix

`public static Jama.Matrix rotationMatrix(double rot)`
Construct a rotation about 0, 0.
Parameters:
`rot` - The amount of rotation in radians.
Returns:
The rotation matrix.
• #### translateToPointMatrix

```public static Jama.Matrix translateToPointMatrix(Point2d from,
Point2d to)```
Given two points, get a transform matrix that takes points from point a to point b
Parameters:
`from` - from this point
`to` - to this point
Returns:
transform matrix
• #### translateMatrix

```public static Jama.Matrix translateMatrix(double x,
double y)```
Construct a translation.
Parameters:
`x` - The amount to translate in the x-direction.
`y` - The amount to translate in the y-direction.
Returns:
The translation matrix.
• #### centeredRotationMatrix

```public static Jama.Matrix centeredRotationMatrix(double rot,
int width,
int height)```
Construct a rotation about the centre of the rectangle defined by width and height (i.e. width/2, height/2).
Parameters:
`rot` - The amount of rotation in radians.
`width` - The width of the rectangle.
`height` - The height of the rectangle.
Returns:
The rotation matrix.

```public static Jama.Matrix scaleMatrixAboutPoint(double sx,
double sy,
int tx,
int ty)```
Create a scaling centered around a point.
Parameters:
`sx` - x-scale
`sy` - y-scale
`tx` - x-position
`ty` - y-position
Returns:
The scaling transform.

```public static Jama.Matrix scaleMatrixAboutPoint(double sx,
double sy,
Point2d point)```
Create a scaling centered around a point.
Parameters:
`sx` - x-scale
`sy` - y-scale
`point` - The point
Returns:
The scaling transform.

```public static Jama.Matrix rotationMatrixAboutPoint(double rot,
float tx,
float ty)```
Construct a rotation about the centre of the rectangle defined by width and height (i.e. width/2, height/2).
Parameters:
`rot` - The amount of rotation in radians.
`tx` - the x translation
`ty` - the y translation
Returns:
The rotation matrix.
• #### affineMatrixND

```@Reference(author="Sp\"ath, Helmuth",
title="Fitting affine and orthogonal transformations between two sets of points.",
type=Article,
year="2004",
journal="Mathematical Communications",
publisher="Croatian Mathematical Society, Division Osijek, Osijek; Faculty of Electrical Engineering, University of Osijek, Osijek",
pages={"27","34"},
volume="9",
number="1")
public static Jama.Matrix affineMatrixND(double[][] q,
double[][] p)```
Find the affine transform between pairs of matching points in n-dimensional space. The transform is the "best" possible in the least-squares sense.
Parameters:
`q` - first set of points
`p` - second set of points
Returns:
least-squares estimated affine transform matrix
• #### affineMatrixND

```@Reference(author="Sp\"ath, Helmuth",
title="Fitting affine and orthogonal transformations between two sets of points.",
type=Article,
year="2004",
journal="Mathematical Communications",
publisher="Croatian Mathematical Society, Division Osijek, Osijek; Faculty of Electrical Engineering, University of Osijek, Osijek",
pages={"27","34"},
volume="9",
number="1")
public static Jama.Matrix affineMatrixND(List<? extends IndependentPair<? extends Coordinate,? extends Coordinate>> data)```
Find the affine transform between pairs of matching points in n-dimensional space. The transform is the "best" possible in the least-squares sense.
Parameters:
`data` - pairs of matching n-dimensional `Coordinate`s
Returns:
least-squares estimated affine transform matrix
• #### rigidMatrix

```@Reference(type=Article,
author={"Berthold K. P. Horn","H.M. Hilden","Shariar Negahdaripour"},
title="Closed-Form Solution of Absolute Orientation using Orthonormal Matrices",
year="1988",
journal="JOURNAL OF THE OPTICAL SOCIETY AMERICA",
pages={"1127","1135"},
number="7",
volume="5")
public static Jama.Matrix rigidMatrix(double[][] q,
double[][] p)```
Compute the least-squares rigid alignment between two sets of matching points in N-dimensional space. Allows scaling and translation but nothing else.
Parameters:
`q` - first set of points
`p` - second set of points
Returns:
rigid transformation matrix.
• #### rigidMatrix

```@Reference(type=Article,
author={"Berthold K. P. Horn","H.M. Hilden","Shariar Negahdaripour"},
title="Closed-Form Solution of Absolute Orientation using Orthonormal Matrices",
year="1988",
journal="JOURNAL OF THE OPTICAL SOCIETY AMERICA",
pages={"1127","1135"},
number="7",
volume="5")
public static Jama.Matrix rigidMatrix(List<? extends IndependentPair<? extends Coordinate,? extends Coordinate>> data)```
Compute the least-squares rigid alignment between two sets of matching points in N-dimensional space. Allows scaling and translation but nothing else.
Parameters:
`data` - set of points matching points
Returns:
rigid transformation matrix.
• #### affineMatrix

`public static Jama.Matrix affineMatrix(List<? extends IndependentPair<? extends Point2d,? extends Point2d>> data)`
Construct an affine transform using a least-squares fit of the provided point pairs. There must be at least 3 point pairs for this to work.
Parameters:
`data` - Data to calculate affine matrix from.
Returns:
an affine transform matrix.
• #### scaleMatrix

```public static Jama.Matrix scaleMatrix(double d,
double e)```
Construct a homogeneous scaling transform with the given amounts of scaling.
Parameters:
`d` - Scaling in the x-direction.
`e` - Scaling in the y-direction.
Returns:
a scaling matrix.
• #### getNormalisations

`public static Pair<Jama.Matrix> getNormalisations(List<? extends IndependentPair<? extends Point2d,? extends Point2d>> data)`
Generates the data for normalisation of the points such that each matched point is centered about the origin and also scaled be be within Math.sqrt(2) of the origin. This corrects for some errors which occured when distances between matched points were extremely large.
Parameters:
`data` -
Returns:
the normalisation data
• #### normalise

```public static List<? extends IndependentPair<Point2d,Point2d>> normalise(List<? extends IndependentPair<Point2d,Point2d>> data,
Pair<Jama.Matrix> normalisations)```
Normalise the data, returning a normalised copy.
Parameters:
`data` -
`normalisations` -
Returns:
the normalised data
• #### normalise

```public static IndependentPair<Point2d,Point2d> normalise(IndependentPair<Point2d,Point2d> data,
Pair<Jama.Matrix> normalisations)```
Normalise the data, returning a normalised copy.
Parameters:
`data` - the data
`normalisations` - the normalisation matrices
Returns:
the normalised data
• #### fundamentalMatrix8PtNorm

`public static Jama.Matrix fundamentalMatrix8PtNorm(List<? extends IndependentPair<Point2d,Point2d>> data)`
The normalised 8-point algorithm for estimating the Fundamental matrix
Parameters:
`data` -
Returns:
the estimated Fundamental matrix
• #### fundamentalMatrix8Pt

`public static Jama.Matrix fundamentalMatrix8Pt(List<? extends IndependentPair<Point2d,Point2d>> data)`
The un-normalised 8-point algorithm for estimation of the Fundamental matrix. Only use with pre-normalised data!
Parameters:
`data` -
Returns:
the estimated Fundamental matrix
• #### homographyMatrixNorm

`public static Jama.Matrix homographyMatrixNorm(List<? extends IndependentPair<? extends Point2d,? extends Point2d>> data)`
Compute the least-squares estimate (the normalised Direct Linear Transform approach) of the homography between a set of matching data points. The data is automatically normalised to prevent numerical problems. The returned homography is the one that can be applied to the first set of points to generate the second set.
Parameters:
`data` - the matching points
Returns:
the estimated homography
• #### homographyMatrix

`public static Jama.Matrix homographyMatrix(List<? extends IndependentPair<? extends Point2d,? extends Point2d>> data)`
Compute the least-squares estimate (the normalised Direct Linear Transform approach) of the homography between a set of matching data points. This method is potentially numerically unstable if the data has not been pre-normalised (using `normalise(List, Pair)`). For un-normalised data, use `homographyMatrixNorm(List)` instead.
Parameters:
`data` - the matching points
Returns:
the estimated homography
• #### homographyToAffine

`public static Jama.Matrix homographyToAffine(Jama.Matrix homography)`
Given a point x and y, calculate the 2x2 affine transform component of the 3x3 homography provided such that: H = AH_p H = { {h11,h12,h13}, {h21,h22,h23}, {h31,h32,h33} } H_p = { {1,0,0}, {0,1,0}, {h31,h32,1} } A = { {a11,a12,a13}, {a21,a22,a23}, {0,0,1} } so
Parameters:
`homography` -
Returns:
the estimated Homography
• #### homographyToAffine

```public static Jama.Matrix homographyToAffine(Jama.Matrix homography,
double x,
double y)```
Estimate the closest (in the least-squares sense) affine transform for a homography.
Parameters:
`homography` - the homography
`x` -
`y` -
Returns:
estimated affine transform.
• #### makeTransform

```public static Jama.Matrix makeTransform(Rectangle from,
Rectangle to)```
Create a transform to transform from one rectangle to another.
Parameters:
`from` - first rectangle
`to` - second rectangle
Returns:
the transform
• #### approximateRotationMatrix

`public static Jama.Matrix approximateRotationMatrix(Jama.Matrix approx)`
Given an approximate rotation matrix Q (that doesn't necessarily conform properly to a rotation matrix), return the best estimate of a rotation matrix R such that the Frobenius norm is minimised: min||r-Q||^2_F.

Fundamentally, this works by performing an SVD of the matrix, setting all the singular values to 1 and then reconstructing the input.

Parameters:
`approx` - the initial guess
Returns:
the rotation matrix
• #### rodrigues

`public static double[] rodrigues(Jama.Matrix R)`
Convert a 3D rotation matrix to a Rodrigues rotation vector, which is oriented along the rotation axis, and has magnitude equal to the rotation angle.
Parameters:
`R` - the rotation matrix
Returns:
the Rodrigues rotation vector
• #### rodrigues

`public static Jama.Matrix rodrigues(double[] r)`
Convert a Rodrigues rotation vector to a rotation matrix.
Parameters:
`r` - the Rodrigues rotation vector
Returns:
the rotation matrix