Accelerating the pace of engineering and science

# estimateGeometricTransform

Estimate geometric transform from matching point pairs

## Syntax

• tform = estimateGeometricTransform(matchedPoints1,matchedPoints2,transformType) example
• [tform,inlierpoints1,inlierpoints2] = estimateGeometricTransform(matchedPoints1,matchedPoints2,transformType) example
• [___,status] = estimateGeometricTransform(matchedPoints1,matchedPoints2,transformType) example
• [___] = estimateGeometricTransform(matchedPoints1,matchedPoints2,transformType, Name,Value)

## Description

example

tform = estimateGeometricTransform(matchedPoints1,matchedPoints2,transformType) returns a 2-D geometric transform object, tform. The tform object maps the inliers in matchedPoints1 to the inliers in matchedPoints2.

The function excludes outliers using the M-estimator SAmple Consensus (MSAC) algorithm. The MSAC algorithm is a variant of the Random Sample Consensus (RANSAC) algorithm. Results may not be identical between runs because of the randomized nature of the MSAC algorithm.

example

[tform,inlierpoints1,inlierpoints2] = estimateGeometricTransform(matchedPoints1,matchedPoints2,transformType) returns the corresponding inlier points in inlierpoints1 and inlierpoints2.

example

[___,status] = estimateGeometricTransform(matchedPoints1,matchedPoints2,transformType) returns a status code of 0, 1, or 2. If you do not request the status code output, the function returns an error for conditions that cannot produce results.

[___] = estimateGeometricTransform(matchedPoints1,matchedPoints2,transformType, Name,Value) uses additional options specified by one or more Name,Value pair arguments.

Code Generation Support:
Compile-time constant input: transformType
Supports MATLAB® Function block: No
Code Generation Support, Usage Notes, and Limitations

## Examples

expand all

### Recover a Transformed Image Using SURF Feature Points

Read and display an image and a transformed image.

```original  = imread('cameraman.tif'); imshow(original); title('Base image');
distorted = imresize(original, 0.7); distorted = imrotate(distorted, 31);
figure; imshow(distorted); title('Transformed image');```

Detect and extract features from both images.

```ptsOriginal  = detectSURFFeatures(original);
ptsDistorted = detectSURFFeatures(distorted);
[featuresOriginal,   validPtsOriginal] = extractFeatures(original,  ptsOriginal);
[featuresDistorted, validPtsDistorted] = extractFeatures(distorted, ptsDistorted);```

Match features.

```index_pairs = matchFeatures(featuresOriginal, featuresDistorted);
matchedPtsOriginal  = validPtsOriginal(index_pairs(:,1));
matchedPtsDistorted = validPtsDistorted(index_pairs(:,2));
figure; showMatchedFeatures(original,distorted,matchedPtsOriginal,matchedPtsDistorted);
title('Matched SURF points, including outliers');```

Exclude the outliers, and compute the transformation matrix.

```[tform,inlierPtsDistorted,inlierPtsOriginal] = estimateGeometricTransform(matchedPtsDistorted,matchedPtsOriginal,'similarity');
figure; showMatchedFeatures(original,distorted,inlierPtsOriginal,inlierPtsDistorted);
title('Matched inlier points');```

Recover the original image from the distorted image.

```outputView = imref2d(size(original));
Ir = imwarp(distorted, tform, 'OutputView', outputView);
figure; imshow(Ir); title('Recovered image');```

## Input Arguments

expand all

### matchedPoints1 — Matched points from image 1cornerPoints object | SURFPoints object | MSERRegions object | M-by-2 matrix of [x,y] coordinates

Matched points from image 1, specified as either a cornerPoints object, SURFPoints object, MSERRegions object, or an M-by-2 matrix of [x,y] coordinates. The function excludes outliers using the M-estimator SAmple Consensus (MSAC) algorithm. The MSAC algorithm is a variant of the Random Sample Consensus (RANSAC) algorithm.

### matchedPoints2 — Matched points from image 2cornerPoints object | SURFPoints object | MSERRegions object | M-by-2 matrix of [x,y] coordinates

Matched points from image 2, specified as either a cornerPoints object, SURFPoints object, MSERRegions object, or an M-by-2 matrix of [x,y] coordinates. The function excludes outliers using the M-estimator SAmple Consensus (MSAC) algorithm. The MSAC algorithm is a variant of the Random Sample Consensus (RANSAC) algorithm.

### transformType — Transform type'similarity' | 'affine' | 'projective'

Transform type, specified as one of three character strings. You can set the transform type to either 'similarity', 'affine', or 'projective'. The greater the number of matched pairs of points, the greater the accuracy of the estimated transformation. The minimum number of matched pairs of points for each transform type:

Transform TypeMinimum Number of Matched Pairs of Points
'similarity'2
'affine'3
'projective'4

Data Types: char

### Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Confidence',99 sets the confidence value to 99.

### 'MaxNumTrials' — Maximum random trials1000 (default) | positive integer

Maximum number of random trials for finding the inliers, specified as the comma-separated pair consisting of 'MaxNumTrials' and a positive integer scalar. Increasing this value improves the robustness of the results at the expense of additional computations.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

### 'Confidence' — Confidence of finding maximum number of inliers99 (default) | positive numeric scalar

Confidence of finding the maximum number of inliers, specified as the comma-separated pair consisting of 'Confidence' and a percentage numeric scalar in the range (0 100). Increasing this value improves the robustness of the results at the expense of additional computations.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

### 'MaxDistance' — Maximum distance from point to projection1.5 (default) | positive numeric scalar

Maximum distance in pixels, from a point to the projection of its corresponding point, specified as the comma-separated pair consisting of 'MaxDistance' and a positive numeric scalar. The corresponding projection is based on the estimated transform.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

## Output Arguments

expand all

### tform — Geometric transformationaffine2d object | projective2d object

Geometric transformation, returned as either an affine2d object or a projective2d object.

The returned geometric transformation matrix maps the inliers in matchedPoints1 to the inliers in matchedPoints2. When you set the transformType input to either 'similarity' or 'affine', the function returns an affine2d object. Otherwise, it returns a projective2d object.

### status — Status code0 | 1 | 2

Status code, returned as the value 0, 1, or 2.

statusDescription
0No error.
1matchedPoints1 and matchedPoints2 inputs do not contain enough points.
2Not enough inliers found.

If you do not request the status code output, the function will throw an error for the two conditions that cannot produce results.

Data Types: double

### inlierpoints1 — Inlier points in image 1inlier points

Inlier points in image 1, returned as the same type as the input matching points.

### inlierpoints2 — Inlier points in image 2inlier points

Inlier points in image 2, returned as the same type as the input matching points.