Estimate 3-D geometric transformation from matching point pairs
estimates a 3-D geometric transformation between two sets of 3-D points by mapping the
inliers in the matched points from one set of 3-D points
tform = estgeotform3d(
matchedPoints1 to the inliers in the matched points from the other
set of 3-D points
additionally returns a vector specifying each matched point pair as either an inlier or an
outlier using the input arguments from the previous syntax.
additionally returns a status code indicating whether or not the function could estimate a
transformation and, if not, why it failed. If you do not specify the
status] = estgeotform3d(___)
status output, the function instead returns an error for conditions
that cannot produce results.
[___] = estgeotform3d(___,
specifies additional options using one or more name-value arguments in addition to any
combination of arguments from previous syntaxes. For example,
Confidence=99 sets the confidence value for finding the maximum
number of inliers to
Fit 3-D Geometric Transformation to Point Clouds
Load a point cloud file into the workspace.
ptCloud1 = pcread("teapot.ply")
ptCloud1 = pointCloud with properties: Location: [41472×3 single] Count: 41472 XLimits: [-3 3.4340] YLimits: [-2 2] ZLimits: [0 3.1500] Color:  Normal:  Intensity: 
ptCloud1 = pcdownsample(ptCloud1,"random",0.25);
Create a rigid 3-D transformation object with a 30-degree rotation about the z-axis.
eulerAngles = [0 0 30]; trans = [0 0 0]; tform = rigidtform3d(eulerAngles,trans);
Transform the point cloud using the transformation object.
ptCloud2 = pctransform(ptCloud1,tform);
To introduce noise, add random points to both point clouds.
noise1 = rescale(rand(1000,3),-2,2); ptCloud1 = pointCloud([ptCloud1.Location;noise1]); noise2 = rescale(rand(1000,3),-2,2); ptCloud2 = pointCloud([ptCloud2.Location;noise2]);
Visualize the noisy point clouds.
figure pcshowpair(ptCloud1,ptCloud2) title("Point Clouds With Added Noise")
Extract matched points from the point clouds.
matchedPoints1 = ptCloud1.Location; matchedPoints2 = ptCloud2.Location;
Estimate the rigid transformation between the point clouds.
[tformEst,inlierIndex] = estgeotform3d(matchedPoints1, ... matchedPoints2,"rigid");
Extract the inlier points.
inliersPtCloud1 = transformPointsForward(tformEst, ... matchedPoints1(inlierIndex,:)); inliersPtCloud2 = matchedPoints2(inlierIndex,:);
Visualize the inliers of the aligned point clouds.
figure firstPtCloud = pointCloud(inliersPtCloud1); secondPtCloud = pointCloud(inliersPtCloud2); pcshowpair(firstPtCloud,secondPtCloud) title("Aligned Point Clouds")
matchedPoints1 — Matched points from first image
M-by-3 matrix of
Matched points from first image, specified as an M-by-3 matrix in which each row is a set of (x,y,z) coordinates and M is the number of matched points.
matchedPoints2 — Matched points from second image
M-by-3 matrix of
Matched points from second image, specified as an M-by-3 matrix in which each row is a set of (x,y,z) coordinates and M is the number of matched points.
transformType — Transformation type
Transformation type, specified as
"similarity". Each transform type requires a minimum number of
matched pairs of points to estimate a transformation. You can generally improve the
accuracy of a transformation by using a larger number of matched pairs of points. This
table shows the type of object associated with each transformation type and the minimum
number of matched pairs of points the transformation requires.
|Minimum Number of Matched Pairs of Points|
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Confidence=99 sets the confidence value for finding the
maximum number of inliers to
MaxNumTrials — Maximum random trials
1000 (default) | positive integer
Maximum number of random trials, specified as a positive integer. This value specifies the number of randomized attempts the function makes to find matching point pairs. Specifying a higher value causes the function to perform additional computations, which increases the likelihood of finding inliers.
Confidence — Confidence of finding maximum number of inliers
99 (default) | positive numeric scalar
Confidence of finding the maximum number of inliers, specified as a positive numeric scalar in the range (0, 100). Increasing this value causes the function to perform additional computations, which increases the likelihood of finding a greater number of inliers.
MaxDistance — Maximum distance from point to projection
1.5 (default) | positive numeric scalar
Maximum distance from a point to the projection of the corresponding point,
specified as a positive numeric scalar.
MaxDistance specifies the
maximum distance, in pixels, that a point can differ from the projected location of
its corresponding point to be considered an inlier. The corresponding projection is
based on the estimated transform.
The function checks for a transformation from
matchedPoints2, and then calculates the distance between the
matched points in each pair after applying the transformation. If the distance between
the matched points in a pair is greater than the
value, then the pair is considered an outlier for that transformation. If the distance
is less than
MaxDistance, then the pair is considered an inlier.
tform — Geometric transformation
rigidtform3d object |
Geometric transformation, returned as a
object or a
The returned geometric transformation matrix maps the inliers in
matchedPoints1 to the inliers in
matchedPoints2. The function returns an object specific to the
transformation type specified by the
transformType input argument.
inlierIndex — Inliers
M-by-1 logical vector
Inliers, returned as an M-by-1 logical vector of
M point pairs. Each element contains either a logical true,
1, to indicate the point pair is an inlier, or a logical false,
0, to indicate the point pair is an outlier.
status — Status code
Status code, returned as
2. The status code indicates whether or not the function could
estimate the transformation and, if not, why it failed.
|Not enough inliers found|
If you do not specify the
status code output, the
function returns an error if it cannot produce results.
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 due to the randomized nature of the MSAC algorithm.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version HistoryIntroduced in R2022b
R2022b: Recommended over
Starting in R2022b, many Computer Vision Toolbox™ functions create and perform geometric transformations using the premultiply
convention. However, the
estimateGeometricTransform3D function estimates geometric transformations
using the old postmultiply convention. Although there are no plans to remove
estimateGeometricTransform3D at this time, you can streamline your
geometric transformation workflows by switching to the
function, which supports the premultiply convention. For more information, see Migrate Geometric Transformations to Premultiply Convention.