Main Content


2-D piecewise linear geometric transformation


A PiecewiseLinearTransformation2D object stores information about a 2-D piecewise linear geometric transformation and enables inverse transformations.


You can create a PiecewiseLinearTransformation2D object in these ways.

  • The fitgeotform2d 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.



tform = images.geotrans.PiecewiseLinearTransformation2D(movingPoints,fixedPoints) creates a PiecewiseLinearTransformation2D object that maps control points in the moving image, movingPoints, to control points in the fixed image, fixedPoints, using a piecewise linear transformation. You can select control points using the cpselect function.

Input Arguments

expand all

Control points in the moving image, specified as an m-by-2 matrix, where m is greater than or equal to 4. 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, where m is greater than or equal to 4. Each row specifies the (x, y) coordinate of a control point.

Data Types: double | single


expand all

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

Object Functions

outputLimitsFind output spatial limits given input spatial limits
transformPointsInverseApply inverse geometric transformation


collapse all

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; 5 13; 5 15;  0 13; -5  -10];

Estimate a piecewise linear transformation that fits fixedPoints and movingPoints.

tform = images.geotrans.PiecewiseLinearTransformation2D(movingPoints,fixedPoints)
tform = 
  PiecewiseLinearTransformation2D with properties:

    Dimensionality: 2

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

movingPointsComputed = transformPointsInverse(tform,fixedPoints)
movingPointsComputed = 6×2

   15.0000   30.0000
   15.0000   15.0000
    5.0000   13.0000
    5.0000   15.0000
   -0.0000   13.0000
   -5.0000  -10.0000


In a piecewise linear transformation, linear (affine) transformations are applied separately to each triangular region of the image [1].

  1. Find a Delaunay triangulation of the fixed control points. For more information, see Working with Delaunay Triangulations.

  2. Using the three vertices of each triangle, infer an affine mapping from fixed to moving coordinates. The mapping is affine for each triangle and continuous across the control points, but is not continuously differentiable.

You must define at least two triangles with distinct mappings by specifying at least four non-colinear control point pairs. More control point pairs can yield more triangular regions.

The PiecewiseLinearTransformation2D object removes control points that are vertices of degenerate fold-over triangles. When movingPoints and fixedPoints do not list the control points in the same order, the object may not eliminate all fold-over triangles. To resolve this error, ensure that control points in the moving and fixed image are ordered identically.


[1] Goshtasby, Ardeshir. “Piecewise Linear Mapping Functions for Image Registration.” Pattern Recognition 19, no. 6 (January 1986): 459–66.

Version History

Introduced in R2013b