Main Content

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) specifies options using one or more name-value arguments in addition to any combination of arguments from previous syntaxes. For example, matchFeatures(__,Method="Exhaustive") sets the matching method to Exhaustive.

Examples

collapse all

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

Read the stereo images.

I1 = im2gray(imread("viprectification_deskLeft.png"));
I2 = im2gray(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);

Figure contains an axes object. The axes object contains 4 objects of type image, line.

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");

Figure contains an axes object. The axes object contains 4 objects of type image, line. These objects represent matched points 1, matched points 2.

Input Arguments

collapse all

Features set 1, specified as a binaryFeatures object, an M1-by-N matrix, or as one of the point feature objects described in Point Feature Types. 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 1, specified as a binaryFeatures object, an M1-by-N matrix, or as one of the point feature objects described in Point Feature Types. 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.

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: Method="Exhaustive" sets the matching method to Exhaustive

Matching method, specified as "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 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 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 "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 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.

column representing features 1 with entry 1 and 3 circled and pointing to entry 2 of a column representing features 2

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

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

Version History

Introduced in R2011a