Find matching features
collapse all in page
Syntax
indexPairs = matchFeatures(features1,features2)
[indexPairs,matchmetric]= matchFeatures(features1,features2)
[indexPairs,matchmetric]= matchFeatures(features1,features2,Name=Value)
Description
indexPairs = matchFeatures(features1,features2)
returnsindices of the matching features in the two input feature sets. Theinput feature must be either binaryFeatures objects or matrices.
example
[indexPairs,matchmetric]= matchFeatures(features1,features2)
alsoreturns 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
Open Live Script
Find corresponding interest points between a pair of images using local neighborhoods 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);
Open Live Script
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, 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 2, specified as a binaryFeatures object, an M2-by-N matrix, or as one of the point feature objects described in Point Feature Types. 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 Arguments
collapse all
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 vectorsin |
"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 isless than the threshold set by MatchThreshold
.The function rejects a match when the distance between the featuresis 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
.
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 featuresets, returned as a P-by-2 matrix of P numberof indices. Each index pair corresponds to a matched feature betweenthe 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-1vector. The value of the distances are based on the metric selected.Each ith element in matchmetric
correspondsto the ith row in the indexPairs outputmatrix. When Metric is set to either SAD
or SSD
,the feature vectors are normalized to unit vectors before computation.
Metric | Range | Perfect 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 Featuresfrom Scale-Invariant Keypoints." International Journalof Computer Vision. Volume 60, Number 2, pp. 91–110.
[2] Muja, M., and D. G. Lowe. "Fast Matchingof Binary Features. "Conference on Computer and Robot Vision.CRV, 2012.
[3] Muja, M., and D. G. Lowe. "Fast ApproximateNearest Neighbors with Automatic Algorithm Configuration." InternationalConference 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
expand all
Usage notes and limitations:
Generates platform-dependent library for MATLAB® host when using the
Approximate
method.Generates portable C code for non-host target onlywhen using the
Exhaustive
method.Generates portable C code using a C++ compiler that links to OpenCV libraries when not using the
Exhaustive
method. See Portable C Code Generation for Functions That Use OpenCV Library.'Method'
and'Metric'
mustbe compile-time constants.
Usage notes and limitations:
CUDA® code is generated only for the
exhaustive
matching method. If theApproximate
method is selected, GPU Coder™ issues a warning and generates C/C++ code for this function.
Version History
Introduced in R2011a
See Also
extractFeatures
Topics
- Create Panorama
- Point Feature Types
- What Is Structure from Motion?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.