matchFeatures

Find matching features

Description

example

indexPairs = matchFeatures(features1,features2) returns indices of the matching features in the two input feature sets. The input feature must be either binaryFeatures objects or matrices.

[indexPairs,matchmetric] = matchFeatures(features1,features2) also returns the distance between the matching features, indexed by indexPairs.

[indexPairs,matchmetric] = matchFeatures(features1,features2,Name,Value) includes additional options specified by one or more Name,Value pair arguments.

Examples

collapse all

Find corresponding interest points between a pair of images using local neighbhorhoods and the Harris algorithm.

Read the stereo images.

I1 = rgb2gray(imread('viprectification_deskLeft.png'));
I2 = rgb2gray(imread('viprectification_deskRight.png'));

Find the corners.

points1 = detectHarrisFeatures(I1);
points2 = detectHarrisFeatures(I2);

Extract the neighborhood features.

[features1,valid_points1] = extractFeatures(I1,points1);
[features2,valid_points2] = extractFeatures(I2,points2);

Match the features.

indexPairs = matchFeatures(features1,features2);

Retrieve the locations of the corresponding points for each image.

matchedPoints1 = valid_points1(indexPairs(:,1),:);
matchedPoints2 = valid_points2(indexPairs(:,2),:);

Visualize the corresponding points. You can see the effect of translation between the two images despite several erroneous matches.

figure; showMatchedFeatures(I1,I2,matchedPoints1,matchedPoints2);

Use the SURF local feature detector function to find the corresponding points between two images that are rotated and scaled with respect to each other.

Read the two images.

I1 = imread('cameraman.tif');
I2 = imresize(imrotate(I1,-20),1.2);

Find the SURF features.

points1 = detectSURFFeatures(I1);
points2 = detectSURFFeatures(I2);

Extract the features.

[f1,vpts1] = extractFeatures(I1,points1);
[f2,vpts2] = extractFeatures(I2,points2);

Retrieve the locations of matched points.

indexPairs = matchFeatures(f1,f2) ;
matchedPoints1 = vpts1(indexPairs(:,1));
matchedPoints2 = vpts2(indexPairs(:,2));

Display the matching points. The data still includes several outliers, but you can see the effects of rotation and scaling on the display of matched features.

figure; showMatchedFeatures(I1,I2,matchedPoints1,matchedPoints2);
legend('matched points 1','matched points 2');

Input Arguments

collapse all

Features set 1, specified as a binaryFeatures object or an M1-by-N matrix. The matrix contains M1 features, and N corresponds to the length of each feature vector. You can obtain the binaryFeatures object using the extractFeatures function with the fast retina keypoint (FREAK), Oriented FAST and Rotated BRIEF (ORB), or binary robust invariant scalable keypoints (BRISK) descriptor method.

Features set 2, specified as a binaryFeatures object or an M2-by-N matrix. The matrix contains M2 features and N corresponds to the length of each feature vector. You can obtain the binaryFeatures object using the extractFeatures function with the fast retina keypoint (FREAK), Oriented FAST and Rotated BRIEF (ORB), or binary robust invariant scalable keypoints (BRISK) descriptor method.

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: 'Metric','SSD' specifies the sum of squared differences for the feature matching metric.

Matching method, specified as the comma-separated pair consisting of 'Method' and either 'Exhaustive' or 'Approximate'. The method specifies how nearest neighbors between features1 and features2 are found. Two feature vectors match when the distance between them is less than the threshold set by the MatchThreshold parameter.

'Exhaustive'

Compute the pairwise distance between feature vectors in features1 and features2.

'Approximate'

Use an efficient approximate nearest neighbor search. Use this method for large feature sets. [3]

Matching threshold, specified as the comma-separated pair consisting of 'MatchThreshold' and a scalar percent value in the range (0,100]. The default values are set to either 10.0 for binary feature vectors or to 1.0 for nonbinary feature vectors. You can use the match threshold for selecting the strongest matches. The threshold represents a percent of the distance from a perfect match.

Two feature vectors match when the distance between them is less than the threshold set by MatchThreshold. The function rejects a match when the distance between the features is greater than the value of MatchThreshold. Increase the value to return more matches.

Inputs that are binaryFeatures objects typically require a larger value for the match threshold. The extractFeatures function returns the binaryFeatures objects when extracting FREAK, ORB, or BRISK descriptors.

Ratio threshold, specified as the comma-separated pair consisting of 'MaxRatio' and a scalar ratio value in the range (0,1]. Use the max ratio for rejecting ambiguous matches. Increase this value to return more matches.

Feature matching metric, specified as the comma-separated pair consisting of 'Metric' and either 'SAD' or 'SSD'.

'SAD'Sum of absolute differences
'SSD'Sum of squared differences

This property applies when the input feature sets, features1 and features2, are not binaryFeatures objects. When you specify the features as binaryFeatures objects, the function uses the Hamming distance to compute the similarity metric.

Unique matches, specified as the comma-separated pair consisting of 'Unique' and either false or true. Set this value to true to return only unique matches between features1 and features2.

When you set Unique to false, the function returns all matches between features1 and features2. Multiple features in features1 can match to one feature in features2.

When you set Unique to true, the function performs a forward-backward match to select a unique match. After matching features1 to features2, it matches features2 to features1 and keeps the best match.

Output Arguments

collapse all

Indices of corresponding features between the two input feature sets, returned as a P-by-2 matrix of P number of indices. Each index pair corresponds to a matched feature between the features1 and features2 inputs. The first element indexes the feature in features1. The second element indexes the matching feature in features2.

Distance between matching features, returned as a p-by-1 vector. The value of the distances are based on the metric selected. Each ith element in matchmetric corresponds to the ith row in the indexPairs output matrix. When Metric is set to either SAD or SSD, the feature vectors are normalized to unit vectors before computation.

MetricRangePerfect Match Value
SAD[0, 2*sqrt(size(features1, 2))]. 0
SSD[0,4]0
Hamming[0, features1.NumBits]0

Note

You cannot select the Hamming metric. It is invoked automatically when features1 and features2 inputs are binaryFeatures.

References

[1] Lowe, David G. "Distinctive Image Features from Scale-Invariant Keypoints." International Journal of Computer Vision. Volume 60, Number 2, pp. 91–110.

[2] Muja, M., and D. G. Lowe. "Fast Matching of Binary Features. "Conference on Computer and Robot Vision. CRV, 2012.

[3] Muja, M., and D. G. Lowe. "Fast Approximate Nearest Neighbors with Automatic Algorithm Configuration." International Conference on Computer Vision Theory and Applications.VISAPP, 2009.

[4] Rublee, E., V. Rabaud, K. Konolige and G. Bradski. "ORB: An efficient alternative to SIFT or SURF." In Proceedings of the 2011 International Conference on Computer Vision, 2564–2571. Barcelona, Spain, 2011.

Extended Capabilities

Introduced in R2011a