# PiecewiseLinearTransformation2D

2-D piecewise linear geometric transformation

## Description

A `PiecewiseLinearTransformation2D` object encapsulates a 2-D piecewise linear geometric transformation.

## Creation

You can create a `PiecewiseLinearTransformation2D` object using the following methods:

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

• The `images.geotrans.PiecewiseLinearTransformation2D` function described here. This function creates a `PiecewiseLinearTransformation2D` object using coordinates of fixed points and moving points.

### Syntax

``tform = images.geotrans.PiecewiseLinearTransformation2D(movingPoints,fixedPoints)``

### Description

example

````tform = images.geotrans.PiecewiseLinearTransformation2D(movingPoints,fixedPoints)` creates a `PiecewiseLinearTransformation2D` object given control point coordinates in `movingPoints` and `fixedPoints`, which define matched control points in the moving and fixed images, respectively.```

### Input Arguments

expand all

x- and y-coordinates of control points in the moving image, specified as an m-by-2 matrix. The number of control points m must be greater than or equal to `n`.

Data Types: `double` | `single`

x- and y-coordinates of control points in the fixed image, specified as an m-by-2 matrix. The number of control points m must be greater than or equal to `n`.

Data Types: `double` | `single`

## Properties

expand all

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

Fit a piecewise linear transformation to a set of fixed and moving control points that are actually related by a single global affine2d transformation across the domain.

Create a 2D affine transformation.

```theta = 10; tformAffine = affine2d([cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1])```
```tformAffine = affine2d with properties: T: [3x3 double] Dimensionality: 2 ```

Arbitrarily choose 6 pairs of control points.

`fixedPoints = [10 20; 10 5; 2 3; 0 5; -5 3; -10 -20];`

Apply forward geometric transformation to map fixed points to obtain effect of fixed and moving points that are related by some geometric transformation.

`movingPoints = transformPointsForward(tformAffine,fixedPoints)`
```movingPoints = 13.3210 17.9597 10.7163 3.1876 2.4906 2.6071 0.8682 4.9240 -4.4031 3.8227 -13.3210 -17.9597```

Estimate piecewise linear transformation that maps `movingPoints` to `fixedPoints`.

`tformPiecewiseLinear = images.geotrans.PiecewiseLinearTransformation2D(movingPoints,fixedPoints)`
```tformPiecewiseLinear = PiecewiseLinearTransformation2D with properties: Dimensionality: 2```

Verify the fit of the `PiecewiseLinearTransformation2D` object at the control points.

```movingPointsComputed = transformPointsInverse(tformPiecewiseLinear,fixedPoints); errorInFit = hypot(movingPointsComputed(:,1)-movingPoints(:,1),... movingPointsComputed(:,2)-movingPoints(:,2))```
```errorInFit = 1.0e-15 * 0 0 0.4441 0 0 0```

## Version History

Introduced in R2013b