| Video and Image Processing Blockset™ | ![]() |
Geometric Transformations


Use the Estimate Geometric Transformation block to find the transformation matrix which maps the greatest number of point pairs between two images. A point pair refers to a point in the input image and its related point on the image created using the transformation matrix. You can select to use the RANdom SAmple Consensus (RANSAC) or the Least Median Squares algorithm to exclude outliers and to calculate the transformation matrix. You can also use all input points to calculate the transformation matrix.
| Port | Input/Output | Supported Data Types | Complex Values Supported |
|---|---|---|---|
Pts1/Pts2 | 2xN Matrix, (where N is the maximum number of points) coordinates of the input points |
| No |
Num | Scalar value that represents the number of valid points in Pts1 and Pts 2 |
| No |
TForm | 2x3 or 3x3, the transformation matrix |
| No |
Inlier | 1xN, indicates which points have been used to calculate TForm | Boolean | No |
Ports Pts1 and Pts2 are the points on two images that have the same data type. When Pts 1 and Pts 2 are single or double, the output transformation matrix will also have single or double data type. When Pts1 and Pts2 images are built-in integers, the option is available to set the transformation matrix data type to either Single or Double. The TForm output provides the transformation matrix. The Inlier output port provides the Inlier points on which the transformation matrix is based. This output appears when you select the Output Boolean signal indication which point pairs are inliers checkbox.
The RANSAC algorithm relies
on a distance threshold. A pair of points,
(image a,
Pts1) and
(image b,
Pts 2) is an inlier only when the distance between
and the projection of
based on the transformation matrix
falls within the specified threshold. The distance metric used in
the RANSAC algorithm is as follows:
![]()
The Least Median Squares algorithm assumes at least 50% of the point pairs can be mapped by a transformation matrix. The algorithm does not need to explicitly specify the distance threshold. Instead, it uses the median distance between all input point pairs. The distance metric used in the Least Median of Squares algorithm is as follows:
![]()
For both equations:
is a point in image a (Pts1)
is a point in image b (Pts2)
is the projection of a point
on image a based on transformation matrix H
is the distance between two
point pairs on image b
is the threshold
is the number of points
The smaller the distance metric, the better the transformation matrix and therefore the more accurate the projection image.
The Estimate Geometric Transformation block supports Nonreflective similarity, affine, and projective transformation types, which are described in this section.
Nonreflective similarity transformation supports translation, rotation, and isotropic scaling. It has four degrees of freedom and requires two pairs of points.

The transformation matrix is:
![]()
The projection of a point
by
is:
![]()
affine transformation supports nonisotropic scaling in addition to all transformations that the nonreflective similarity transformation supports. It has six degrees of freedom that can be determined from three pairs of noncollinear points.
![]()
The transformation matrix is:
![]()
The projection of a point
by
is:
![]()
Projective transformation supports tilting in addition to all transformations that the affine transformation supports.
![]()
The transformation matrix is :

The projection of a point
by
is represented by homogeneous
coordinates as:
![]()
For computational simplicity and efficiency, this block uses
algebraic distance. The algebraic distance for a pair of points,
on image a, and
on image b ,
according to transformation
is
defined as follows;
For projective transformation:
, where
![]()
For Nonreflective similarity or affine transformation:
,
where
![]()
The block performs a comparison and repeats it M number of times between successive transformation matrices. If you select the Find and exclude outliers option, the RANSAC and Least Median Squares (LMS) algorithms become available. These algorithms calculate and compare a distance metric. The transformation matrix that produces the smaller distance metric becomes the new transformation matrix that the next comparison uses. A final transformation matrix is resolved when either:
M number of random samplings is performed
The RANSAC algorithm, when enough number of inlier point pairs can be mapped, (dynamically updating M)
The Estimate Geometric Transformation algorithm follows these steps:
A transformation matrix
is
initialized to zeros
Set count = 0 (Randomly sampling).
While count < M , where M is total number of random samplings to perform, perform the following;
Increment the count; count = count + 1.
Randomly select pair of points from images a and b, (2 pairs for Nonreflective similarity, 3 pairs for affine, or 4 pairs for projective).
Calculate a transformation matrix
, from the selected points.
If
has a distance
metric less than that of
,
then replace
with
.
(Optional for RANSAC algorithm only)
Update M dynamically.
Exit out of sampling loop if enough number of point pairs
can be mapped by
.
Use all point pairs in images a and b that
can be mapped by
to calculate a
refined transformation matrix
![]()
Iterative Refinement, (Optional for RANSAC and LMS algorithms)
Denote all point pairs that can be mapped by
as inliers.
Use inlier point pairs to calculate a transformation matrix
.
If
has a distance
metric less than that of
,
then replace
with
, otherwise exit the loop.
The number of random samplings can be specified by the user for the RANSAC and Least Median Squares algorithms. You can use an additional option with the RANSAC algorithm, which calculates this number based on an accuracy requirement. The Desired Confidence level drives the accuracy.
The calculated number of random samplings, M used with the RANSAC algorithm, is as follows:
![]()
where
p is the probability of independent point pairs belonging to the largest group that can be mapped by the same transformation. The probability is dynamically calculated based on the number of inliers found versus the total number of points. As the probability increases, the number of samplings, M , decreases.
q is the probability of finding the largest group that can be mapped by the same transformation.
s is equal to the value 2, 3, or 4 for Nonreflective similarity, affine, and projective transformation, respectively.
The transformation matrix calculated from all inliers can be used to calculate a refined transformation matrix. The refined transformation matrix is then used to find a new set of inliers. This procedure can be repeated until the transformation matrix cannot be further improved. This iterative refinement is optional.

Specify transformation type, either Nonreflective similarity, affine, or projective transformation. If you select projective transformation, you can also specify a scalar algebraic distance threshold for determining inliers. If you select either affine or projective transformation, you can specify the distance threshold for determining inliers in pixels. See Transformations for a more detailed discussion.
When selected, the block finds and excludes outliers from the input points and uses only the inlier points to calculate the transformation matrix. When this option is not selected, all input points are used to calculate the transformation matrix.
Select either the RANdom SAmple Consensus (RANSAC) or the Least Median of Squares algorithm to find outliers. See RANSAC and Least Median Squares Algorithms for a more detailed discussion.
Specify a scalar threshold value for determining inliers. The threshold controls the upper limit used to find the algebraic distance in the RANSAC algorithm. This parameter appears when the Method parameter is Random Sample Consensus (RANSAC) and the Transformation type parameter is projective.
Specify the upper limit distance a point can differ from the projection location of its associating point. This parameter appears when the Method parameter is set to Random Sample Consensus (RANSAC) and the value of the Transformation type parameter is set to Nonreflective similarity or affine
Select Specified value to enter a positive integer value for number of random samplings, or select Desired confidence to set the number of random samplings as a percentage and a maximum number. This parameter appears when you select Find and exclude outliers parameter, and the value of the Method parameter is Random Sample Consensus (RANSAC).
Specify the number of random samplings for the algorithm to perform. This parameter appears when the value of the Determine number of random samplings using parameter is Specified value.
Specify a percent by entering a number between 0 and 100. The Desired confidence is the probability to find the largest group of points that can be mapped by a transformation matrix. This parameter is visible when the Determine number of random samplings using is Desired confidence.
Specify an integer number for the maximum number of random samplings. This parameter appears when the Method parameter is set to Random Sample Consensus (RANSAC) and the value of Determine number of random samplings using parameter is Desired confidence.
Specify to stop random sampling when a percentage of input points have been found as inliers. This parameter appears when the Method parameter is Random Sample Consensus (RANSAC).
Specify whether to perform refinement on the transformation matrix. This parameter appears when you select Find and exclude outliers parameter.
Select this option to output the inlier point pairs that were used to calculate the transformation matrix. This parameter appears when you select Find and exclude outliers parameter. This parameter is not used when the data type of points is signed or double.
Specify transformation matrix data type as Single or Double when the input points are built-in integers. This parameter is not used when the data type of points is signed or double.
| Parameter Name | Default Value | Visibility | Tunability |
|---|---|---|---|
Transformation type | projective | Always | No |
Find and exclude outliers | Checked | Always | No |
Method | RANSAC | Visible when Find and exclude outliers parameter is selected | No |
Algebraic distance threshold for determining inliers | 1.5 | Visible when Method parameter is Random Sample Consensus (RANSAC) and the Transformatinon type parameter is projective | Yes |
Distance threshold for determining inliers (in pixels) | 1.5 | Visible when Method parameter is Random Sample Consensus (RANSAC) and the Transformatinon type parameter is Nonreflective similarity or affine | Yes |
Determine number of random samplings | Specified value | Visible when Find and exclude outliers parameter is selected | No |
Number of random samplings | 100 | Visible when Determine number of random samplings using parameter is Specified value | Yes |
Maximum number of random samplings | 200 | Visible when the Method parameter is set to Random Sample Consensus (RANSAC) and Determine number of random samplings using parameter is Desired confidence | Yes |
Desired confidence (in%) | 99 | Visible when the Determine number of random samplings using is Desired confidence | Yes |
Stop sampling earlier when a specified percentage of point pairs are determined to be inliers | Unchecked | Visible when the Method parameter is Random Sample Consensus (RANSAC) | No |
Inlier percentage | 75 | Visible when Stop sampling earlier when a specified percentage of point pairs are determined to be inliers parameter is checked | Yes |
Perform additional iterative refinement of the transformation matrix | Unchecked | Visible when Find and exclude outliers parameter is selected | No |
Output Boolean signal indicating which input points are inliers | Unchecked | Visible when Find and exclude outliers parameter is selected | No |
When Pts1 and Pts2 are built-in integers, set transformation matrix data type to | Single | Always | No |
Examples of input data and application of the Estimate Geometric Transformation block appear in the following figures. Figures (a) and (b) show the point pairs. The points are denoted by stars or circles, and the numbers following them show how they are paired. Some point pairs can be mapped by the same transformation matrix. Other point pairs require a different transformation matrix. One matrix exists that maps the largest number of point pairs, the block calculates and returns this matrix. The block finds the point pairs in the largest group and uses them to calculate the transformation matrix. The point pairs connected by the magenta lines are the largest group.
The transformation matrix can then be used to stitch the images as shown in Figure (e).

To see an example of the Estimate Geometric Transformation block used in a model with other blocks, see the Video Mosaicking Demo, vipmosaicking.
R. Hartley and A. Ziserman, "Multiple View Geometry in Computer Vision," Second edition, Cambridge University Press, 2003
Image Processing Toolbox software | |
| vipmosaicking | Video and Image Processing Blockset demo |
![]() | Erosion | Find Local Maxima | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |