Main Content

pcmatchfeatures

Find matching features between point clouds

Since R2020b

Description

indexPairs = pcmatchfeatures(features1,features2) finds matching features between the input matrices of extracted point cloud features and returns their indices within each feature matrix.

indexPairs = pcmatchfeatures(features1,features2,ptCloud1,ptCloud2) rejects ambiguous feature matches based on spatial relation information from the point clouds corresponding to the feature matrices.

example

[indexPairs,scores] = pcmatchfeatures(___) returns the normalized Euclidean distances between the matching features using any combination of input arguments from previous syntaxes.

[___] = pcmatchfeatures(___,Name,Value) specifies options using one or more name-value pair arguments in addition to any combination of arguments in previous syntaxes. For example, 'MatchThreshold',0.03 sets the normalized distance threshold for matching features to 0.03.

Examples

collapse all

This example shows how to match corresponding point cloud features using the pcmatchfeatures function.

Preprocessing

Read point cloud data into the workspace.

ptCld = pcread("teapot.ply");

Downsample the point cloud.

ptCloud = pcdownsample(ptCld,"gridAverage",0.05);

Transform and create a new point cloud using the transformation matrix A.

A = [cos(pi/6) -sin(pi/6) 0 5; ...
     sin(pi/6)  cos(pi/6) 0 5; ...
            0         0   1 10; ...
            0         0   0 1];     
tform = affinetform3d(A);
ptCloudTformed = pctransform(ptCloud,tform);

Visualize the two point clouds.

pcshowpair(ptCloud,ptCloudTformed);
legend("Original", "Transformed","TextColor",[1 1 0]);

Figure contains an axes object. The axes object contains 2 objects of type scatter. These objects represent Original, Transformed.

Match Corresponding Features

In the preprocessing section, we created a second point cloud by translating and rotating the original point cloud. In this section, we use the pcmatchfeatures function to find matching features between these point clouds.

Extract features from both the point clouds using the extractFPFHFeatures function.

fixedFeature = extractFPFHFeatures(ptCloud);
movingFeature = extractFPFHFeatures(ptCloudTformed);
length(movingFeature)
ans = 
16578

Find matching features.

[matchingPairs,scores] = pcmatchfeatures(fixedFeature,movingFeature,ptCloud,ptCloudTformed);
length(matchingPairs)
ans = 
3412

A score close to zero means that the algorithm is confident about a match and vice-versa. Calculate the mean score for all the matches using the scores vector.

mean(scores)
ans = 
0.0017

Input Arguments

collapse all

First feature set, specified as an M1-by-N matrix. The matrix contains M1 features, and N is the length of each feature vector. Each row represents a single feature.

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

Second feature set, specified as an M2-by-N matrix. The matrix contains M2 features, and N is the length of each feature vector. Each row represents a single feature.

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

First point cloud, specified as a pointCloud object.

Second point cloud, specified as a pointCloud object.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is 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.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'MatchThreshold',0.03 sets the normalized distance threshold for matching features to 0.03.

Matching method, specified as the comma-separated pair consisting of 'Method' and either 'Exhaustive' or 'Approximate'. The method determines how the function finds the nearest neighbors between features1 and features2. Two feature vectors match when the distance between them is less than or equal to the matching threshold.

  • 'Exhaustive' — Compute the pairwise distance between the specified feature vectors.

  • 'Approximate' — Use an efficient approximate nearest neighbor search. Use this method for large feature sets. For more information about the algorithm, see [1]

Data Types: char | string

Matching threshold, specified as the comma-separated pair consisting of 'MatchThreshold' and a scalar in the range (0, 1].

Two feature vectors match when the normalized Euclidean distance between them is less than or equal to the matching threshold. A higher value may result in additional matches, but increases the risk of false positives.

Data Types: single | double

Spatial relation threshold, specified as the comma-separated pair consisting of 'RejectRatio' and a scalar in the range (0,1).

The function uses point cloud data to estimate the spatial relation between the points associated with potential feature matches and reject matches based on the spatial relation threshold. A lower spatial relation threshold may result in additional matches, but increases the risk of false positives.

The function does not consider the spatial relation threshold if you do not specify values for the ptCloud1 and ptCloud2 input arguments.

Note

At least three features must be matched between the feature matrices to consider the spatial relation.

Data Types: single | double

Output Arguments

collapse all

Indices of matched features, returned as a P-by-2 matrix. P is the number of matched features. Each row corresponds to a matched feature between the features1 and features2 inputs, where the first element is the index of the feature in features1 and the second element is the index of the matching feature in features2.

Data Types: uint32

Normalized Euclidean distance between matching features, returned as a P-element column vector. The ith element of the vector is the distance between the matched features in the ith row of the indexPairs output.

Data Types: single | double

References

[1] Muja, Marius and David G. Lowe. "Fast Approximate Nearest Neighbors with Automatic Algorithm Configuration." In Proceedings of the Fourth International Conference on Computer Vision Theory and Applications, 331-40. Lisboa, Portugal: SciTePress - Science and Technology Publications, 2009. https://doi.org/10.5220/0001787803310340.

[2] Zhou, Qian-Yi, Jaesik Park, and Vladlen Koltun. "Fast global registration." In European Conference on Computer Vision, pp. 766-782. Springer, Cham, 2016.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2020b