Find matching features between point clouds
___ = pcmatchfeatures(___,
specifies options using one or more name-value pair arguments in addition to any combination
of arguments in previous syntaxes. For example,
sets the normalized distance threshold for matching features to
This example shows how to match corresponding point cloud features and visualize them using the
veloReader = velodyneFileReader('lidarData_ConstructionRoad.pcap','HDL32E');
Read two point clouds using the
frameNumber = 1; skipFrame = 5; fixed = readFrame(veloReader,frameNumber); moving = readFrame(veloReader,frameNumber + skipFrame);
Segment and remove the ground plane from the fixed point cloud.
groundPtsIdxFixed = segmentGroundFromLidarData(fixed); fixedSeg = select(fixed,~groundPtsIdxFixed,'OutputSize','full');
Segment and remove the ground plane from the moving point cloud. Plot both point clouds.
groundPtsIdxMoving = segmentGroundFromLidarData(moving); movingSeg = select(moving,~groundPtsIdxMoving,'OutputSize','full'); figure pcshowpair(fixedSeg,movingSeg) ylim([-50 60]) title('Input Point Clouds')
The superimposed input point clouds are color coded as follows:
Magenta - Fixed point cloud
Green - Moving Point Cloud
Downsample the point clouds.
fixedDownsampled = pcdownsample(fixedSeg,'gridAverage',0.2); movingDownsampled = pcdownsample(movingSeg,'gridAverage',0.2);
Extract features from the point clouds.
[fixedFeature,fixedValidInds] = extractFPFHFeatures(fixedDownsampled); [movingFeature,movingValidInds] = extractFPFHFeatures(movingDownsampled); fixedValidPts = select(fixedDownsampled,fixedValidInds); movingValidPts = select(movingDownsampled,movingValidInds);
Match features between the point clouds.
indexPairs = pcmatchfeatures(movingFeature,fixedFeature,movingValidPts, ... fixedValidPts); matchedFixedPts = select(fixedValidPts,indexPairs(:,2)); matchedMovingPts = select(movingValidPts,indexPairs(:,1));
Visualize the matches.
figure pcshowMatchedFeatures(movingSeg,fixedSeg,matchedMovingPts,matchedFixedPts, ... 'Method',"montage") xlim([-40 210]) ylim([-50 50]) title('Matched Points')
The matched features and point clouds are color coded to improve visualization:
Magenta - Moving point cloud.
Green - Fixed point cloud.
Red circle - Matched points in the moving point cloud.
Blue asterisk - Matched points in the fixed point cloud.
Yellow - Line connecting matched features.
features1— First feature set
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.
features2— Second feature set
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.
ptCloud2— Second point cloud
Second point cloud, specified as a
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
'MatchThreshold',0.03sets the normalized distance threshold for matching features to
'Method'— Matching method
Matching method, specified as the comma-separated pair consisting of
'Method' and either
'Approximate'. The method determines how the function finds the
nearest neighbors between
features2. Two feature vectors match when the distance between
them is less 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. 
'MatchThreshold'— Matching threshold
0.01(default) | scalar in the range (
Matching threshold, specified as the comma-separated pair consisting of
'MatchThreshold' and a scalar in the range (
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.
'RejectRatio'— Spatial relation threshold
0.95(default) | scalar in the range (
Spatial relation threshold, specified as the comma-separated pair consisting of
'RejectRatio' and a scalar in the range (
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.
indexPairs— Indices of matched features
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
features2 inputs, where the first element is the index of the
features1 and the second element is the index of the
matching feature in
scores— Normalized Euclidean distance between matching features
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
 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.
 Zhou, Qian-Yi, Jaesik Park, and Vladlen Koltun. "Fast global registration." In European Conference on Computer Vision, pp. 766-782. Springer, Cham, 2016.