INDEX_PAIRS = matchFeatures(FEATURES1, FEATURES2)
返回INDEX_PAIRS为[P,2]数组,包含最可能相关的特征点的数组。FEATURES1为[M1,N]的数组,FEATURES2为[M2,N]的数组,都可以是由FREAK描述子产生的二值特征。
[INDEX_PAIRS, MATCH_METRIC] = matchFeatures(FEATURES1, FEATURES2, ...)
除了上述返回值,还返回和INDEX_PAIRS相关的度量值MATCH_METRIC,他是[P,1]的数组。
[INDEX_PAIRS, MATCH_METRIC] = matchFeatures(...,Name, Value) specifies
附加name-value可以为:
'Method' 两个特征向量之间的距离小于MatchThreshold设置的阈值时他们为匹配的。有三种:
Default: 'NearestNeighborRatio'‘Threshold’:只是用匹配阈值。每个特征点能返回多个匹配点。
‘NearestNeighborSymmetric’:使用匹配阈值且只返回一个匹配点。只选择最近邻的匹配点。
'NearestNeighborRatio':使用匹配且消除了模糊匹配。只有当两特征点之间的最近距离满足一定比率,才符合。比率为特征点到第一个最近邻和到第二个最近邻之间的比值。
‘MatchThreshold’ 0 < T <= 100。大于百分之T的特征点确定为匹配点。减小T可获得更多匹配。
Default: 10.0 for binary feature vectors (二分特征向量)1.0 otherwise
Default: 0.6
'Metric' 字符串,当FEATURES1和FEATURES2是binaryFeatures式不可用。
'SAD' : Sum of absolute differences
'SSD' : Sum of squared differences
'normxcorr' : Normalized cross-correlation
Default: 'SSD'
注意:当FATURES1和FEATURES2是binaryFeatures时,使用Hamming 距离来计算相似的度量。
'Prenormalized' 逻辑标量。TRUE表示FEATURES1和FEATURES2在匹配前已经正规化到单元向量。设置FALSE会导致FEATURES1和FEATURES2的正规化。注意,如果匹配前没有正规化将产生错误结果。FEATURES1和FEATURES2是binaryFeature的时候,参数不可用。
Default: false
注意:
% Notes
% -----
% The range of values of MATCH_METRIC varies as a function of the feature
% matching metric being used. Prior to computation of SAD and SSD
% metrics, the feature vectors are normalized to unit vectors. The table
% below summarizes the metric ranges and perfect match values:
%
% Metric Range Perfect Match Value
% ---------- ------------------------------- -------------------
% SAD [0, 2*sqrt(size(FEATURES1, 1))] 0
% SSD [0, 4] 0
% normxcorr [-1, 1] 1
%
% Hamming [0, FEATURES1.NumBits] 0
%
matlab:函数文档
%matchFeatures Find matching features
% INDEX_PAIRS = matchFeatures(FEATURES1, FEATURES2) returns a P-by-2
% matrix, INDEX_PAIRS, containing indices to the features most likely to
% correspond between the two input feature matrices. The function takes
% two inputs, FEATURES1, an M1-by-N matrix, and FEATURES2, an M2-by-N
% matrix. FEATURES1 and FEATURES2 can also be binaryFeatures objects in
% the case of binary descriptors produced by the FREAK descriptor.
%
% [INDEX_PAIRS, MATCH_METRIC] = matchFeatures(FEATURES1, FEATURES2, ...)
% also returns the metric values that correspond to the associated
% features indexed by INDEX_PAIRS in a P-by-1 matrix MATCH_METRIC.
%
% [INDEX_PAIRS, MATCH_METRIC] = matchFeatures(...,Name, Value) specifies
% additional name-value pairs described below:
%
% 'Method' A string used to specify the matching strategy. All
% three methods use the match threshold. Two feature
% vectors match when the distance between them is less
% than the threshold set by the MatchThreshold
% parameter. Set the method to one of the following:
%
% 'Threshold': Only uses the match threshold. This
% method can return more than one match for each
% feature.
%
% 'NearestNeighborSymmetric': Only returns unique
% matches in addition to using the match threshold.
% A feature vector only matches to its nearest
% neighbor in the other feature set.
%
% 'NearestNeighborRatio': Eliminates ambiguous matches
% in addition to using the match threshold. A
% feature vector is matched to its nearest neighbor
% in the other feature set, when the nearest
% neighbor satisfies a ratio test. The ratio test
% compares the distances from the feature vector to
% its first and second nearest neighbors in the
% other feature set.
%
% Default: 'NearestNeighborRatio'
%
% 'MatchThreshold' A scalar T, 0 < T <= 100, specifying a threshold
% for selecting the strongest matches. Matches having
% metrics more than T percent from a perfect match
% are rejected. Increase T to return more matches.
%
% Default: 10.0 for binary feature vectors
% 1.0 otherwise
%
% 'MaxRatio' A scalar R, 0 < R <= 1, specifying a ratio threshold
% for rejecting ambiguous matches. Increase R to return
% more matches. This parameter is used only with
% 'NearestNeighborRatio' method.
%
% Default: 0.6
%
% 'Metric' A string used to specify the feature matching
% metric. This parameter is not applicable when
% FEATURES1 and FEATURES2 are binaryFeatures objects.
% Possible values are:
% 'SAD' : Sum of absolute differences
% 'SSD' : Sum of squared differences
% 'normxcorr' : Normalized cross-correlation
%
% Default: 'SSD'
%
% Note: When FEATURES1 and FEATURES2 are binaryFeatures
% objects, Hamming distance is used to compute
% the similarity metric.
%
% 'Prenormalized' A logical scalar. Use true to indicate that FEATURES1
% and FEATURES2 are already normalized to unit vectors
% prior to matching. Setting this flag to false will
% result in normalizing FEATURES1 and FEATURES2. Note
% that setting this flag to true when features are not
% normalized in advance will produce wrong results.
% This parameter is not applicable when FEATURES1 and
% FEATURES2 are binaryFeatures objects.
%
% Default: false
%
% Notes
% -----
% The range of values of MATCH_METRIC varies as a function of the feature
% matching metric being used. Prior to computation of SAD and SSD
% metrics, the feature vectors are normalized to unit vectors. The table
% below summarizes the metric ranges and perfect match values:
%
% Metric Range Perfect Match Value
% ---------- ------------------------------- -------------------
% SAD [0, 2*sqrt(size(FEATURES1, 1))] 0
% SSD [0, 4] 0
% normxcorr [-1, 1] 1
%
% Hamming [0, FEATURES1.NumBits] 0
%
% This function changed in the release R2012b. Previous versions
% used a different matching strategy. If you need the same results
% produced by the previous implementation, use
% matchFeatures(FEATURES1, FEATURES2, 'Method', 'NearestNeighbor_old',...).
%
% Class Support
% -------------
% FEATURES1 and FEATURES2 can be logical, int8, uint8, int16, uint16,
% int32, uint32, single, double, or binaryFeatures object.
%
% The output class of INDEX_PAIRS is uint32. MATCH_METRIC is double when
% FEATURES1 and FEATURES2 are double. Otherwise, it is single.
%
% Example 1
% ---------
% % Find corresponding interest points between a pair of images using
% % local neighborhoods.
% I1 = rgb2gray(imread('viprectification_deskLeft.png'));
% I2 = rgb2gray(imread('viprectification_deskRight.png'));
%
% % Find corners
% points1 = detectHarrisFeatures(I1);
% points2 = detectHarrisFeatures(I2);
%
% % Extract neighborhood features
% [features1, valid_points1] = extractFeatures(I1, points1);
% [features2, valid_points2] = extractFeatures(I2, points2);
%
% % Match features
% index_pairs = matchFeatures(features1, features2);
%
% % Retrieve locations of corresponding points for each image
% matched_points1 = valid_points1(index_pairs(:, 1), :);
% matched_points2 = valid_points2(index_pairs(:, 2), :);
%
% % Note that you can clearly see the effect of translation
% % between the two images despite several erroneous matches.
% figure; showMatchedFeatures(I1, I2, matched_points1, matched_points2);
%
% Example 2
% ---------
% % Use SURF features to find corresponding points between two images
% % rotated and scaled with respect to each other
% I1 = imread('cameraman.tif');
% I2 = imresize(imrotate(I1,-20), 1.2);
%
% points1 = detectSURFFeatures(I1);
% points2 = detectSURFFeatures(I2);
%
% [f1, vpts1] = extractFeatures(I1, points1);
% [f2, vpts2] = extractFeatures(I2, points2);
%
% % SURF feature vectors are already normalized.
% index_pairs = matchFeatures(f1, f2, 'Prenormalized', true);
% matched_pts1 = vpts1(index_pairs(:, 1));
% matched_pts2 = vpts2(index_pairs(:, 2));
%
% % Note that there are still several outliers present in the data, but
% % otherwise you can clearly see the effects of rotation and scaling on
% % the display of matched features.
% figure; showMatchedFeatures(I1,I2,matched_pts1,matched_pts2);
% legend('matched points 1','matched points 2');
%
% See also showMatchedFeatures, vision.CornerDetector, detectSURFFeatures,
% detectMSERFeatures, extractFeatures, estimateFundamentalMatrix,
% estimateGeometricTransform, binaryFeatures.
% Copyright 2011 The MathWorks, Inc.
%
% We use the normalized cross-correlation as defined in this paper:
%
% "Fast Normalized Cross-Correlation", by J. P. Lewis, Industrial
% Light & Magic.
%
% We implement the nearest-neighbor ratio method as defined in
% this paper:
%
% David Lowe, "Distinctive image features from scale-invariant
% keypoints," International Journal of Computer Vision, 60, 2 (2004)
%
% The three matching strategies are described in this paper:
%
% K. Mikolajczyk and C. Shmid, "A Performance Evaluation of Local
% Descriptors," IEEE PAMI, 27, 10 (2005)