# PolynomialTransformation2D

2-D polynomial geometric transformation

## Description

A `PolynomialTransformation2D` object stores information about a 2-D polynomial geometric transformation and enables inverse transformations.

## Creation

You can create a `PolynomialTransformation2D` object in these ways.

• The `fitgeotform2d` function, which estimates a geometric transformation that maps pairs of control points between two images.

• The `images.geotrans.PolynomialTransformation2D` function described here. This function creates a `PolynomialTransformation2D` object using coordinates of fixed points and moving points, or the known polynomial coefficients for the forward and inverse transformation.

### Syntax

``tform = images.geotrans.PolynomialTransformation2D(movingPoints,fixedPoints,degree)``
``tform = images.geotrans.PolynomialTransformation2D(a,b)``

### Description

example

````tform = images.geotrans.PolynomialTransformation2D(movingPoints,fixedPoints,degree)` creates a `PolynomialTransformation2D` object and sets the `Degree` property. The function estimates the polynomial coefficients that map control points in the moving image, `movingPoints`, to control points in the fixed image, `fixedPoints`. You can select control points using the `cpselect` function.```
````tform = images.geotrans.PolynomialTransformation2D(a,b)` creates a `PolynomialTransformation2D` object and sets the `A` and `B` properties using the specified polynomial coefficients.```

### Input Arguments

expand all

Control points in the moving image, specified as an m-by-2 matrix. Each row specifies the (x, y) coordinate of a control point.

Data Types: `double` | `single`

Control points in the fixed image, specified as an m-by-2 matrix. Each row specifies the (x, y) coordinate of a control point.

Data Types: `double` | `single`

## Properties

expand all

Polynomial coefficients used to determine U in the inverse transformation, specified as an n-element vector. For polynomials of degree 2, 3, and 4, n is 6, 10, and 15, respectively.

The quadratic (degree 2) polynomial coefficient vector `A` is ordered as follows:

`U = A(1) + A(2).*X + A(3).*Y + A(4).*X.*Y + A(5).*X.^2 + A(6).*Y.^2`

The cubic (degree 3) polynomial coefficient vector adds these terms:

`... + A(7).*X.^2.*Y + A(8).*X.*Y.^2 + A(9).*X.^3 + A(10).*Y.^3`

The quartic (degree 4) polynomial coefficient vector adds these terms:

`... + A(11).*X.^3.*Y + A(12).*X.^2.*Y.^2 + A(12).*X.*Y.^3 + A(14).*X.^3 + A(15).*Y.^4`

Data Types: `double` | `single`

Polynomial coefficients used to determine V in the inverse transformation, specified as an n-element vector. For polynomials of degree 2, 3, and 4, n is 6, 10, and 15, respectively.

The quadratic (degree 2) polynomial coefficient vector `B` is ordered as follows:

`V = B(1) + B(2).*X + B(3).*Y + B(4).*X.*Y + B(5).*X.^2 + B(6).*Y.^2`

The cubic (degree 3) polynomial coefficient vector adds these terms:

`... + B(7).*X.^2.*Y + B(8).*X.*Y.^2 + B(9).*X.^3 + B(10).*Y.^3`

The quartic (degree 4) polynomial coefficient vector adds these terms:

`... + B(11).*X.^3.*Y + B(12).*X.^2.*Y.^2 + B(12).*X.*Y.^3 + B(14).*X.^3 + B(15).*Y.^4`

Data Types: `double` | `single`

Degree of the polynomial transformation, specified as the integer `2`, `3`, or `4`.

Dimensionality of the geometric transformation for both input and output points, specified as the value `2`.

## Object Functions

 `outputLimits` Find output spatial limits given input spatial limits `transformPointsInverse` Apply inverse geometric transformation

## Examples

collapse all

A second degree polynomial requires six pairs of control points. Choose six pairs of control points and moving points. For simplicity, this example selects moving points that are translated 5 pixels horizontally and 10 pixels vertically from the fixed points.

```fixedPoints = [10 20; 10 5; 2 3; 0 5; -5 3; -10 -20]; movingPoints = [15 30; 15 15; 7 13; 5 15; 0 13; -5 -10];```

Estimate a second degree polynomial transformation that fits `fixedPoints` and `movingPoints`.

`tformPolynomial = images.geotrans.PolynomialTransformation2D(movingPoints,fixedPoints,2)`
```tformPolynomial = PolynomialTransformation2D with properties: Dimensionality: 2 Degree: 2 A: [1.1102e-16 1.0000 8.1148e-17 3.1692e-15 -6.0409e-16 ... ] B: [1.1842e-16 -8.6803e-16 1.0000 5.5598e-15 ... ] ```

Verify that the inverse transformation maps the fixed points to the moving points.

`movingPointsEstimated = transformPointsInverse(tformPolynomial,fixedPoints)`
```movingPointsEstimated = 6×2 15.0000 30.0000 15.0000 15.0000 7.0000 13.0000 5.0000 15.0000 0.0000 13.0000 -5.0000 -10.0000 ```