Main Content

pcmatchfeatures

Find matching features between point clouds

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.

example

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

[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 and visualize them using the pcmatchfeatures and pcshowMatchedFeatures functions.

Construct a velodyneFileReader object.

veloReader = velodyneFileReader('lidarData_ConstructionRoad.pcap','HDL32E');

Read two point clouds using the velodyneFileReader object.

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.

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 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 quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

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 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. [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.

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™.

Introduced in R2020b