主要内容

本页采用了机器翻译。点击此处可查看英文原文。

matchFeatures

查找匹配的特征

说明

indexPairs = matchFeatures(features1,features2) 返回两个输入特征集中共匹配特征的索引。输入特征必须是 binaryFeatures 对象或矩阵。

示例

[indexPairs,matchmetric] = matchFeatures(features1,features2) 还会返回匹配特征之间的距离,该距离以 indexPairs 为索引。

[indexPairs,matchmetric] = matchFeatures(features1,features2,Name=Value) 支持上述语法中的任何参量组合,且可使用一个或多个名称-值参量指定选项。例如,matchFeatures(__,Method="Exhaustive") 将匹配方法设置为 Exhaustive

示例

全部折叠

利用局部邻域和哈里斯算法,在一对图像之间查找相应的兴趣点。

读取立体图像。

I1 = im2gray(imread("viprectification_deskLeft.png"));
I2 = im2gray(imread("viprectification_deskRight.png"));

找到角点。

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

提取邻域特征。

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

将特征进行匹配。

indexPairs = matchFeatures(features1,features2);

获取每个图像中相应点的坐标。

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

将相应的点可视化。尽管存在几处错误匹配,但从这两个图像中仍可看出翻译的效果。

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

Figure contains an axes object. The hidden axes object contains 4 objects of type image, line. One or more of the lines displays its values using only markers

读取这两个图像。

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

查找 SURF 特征。

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

提取特征。

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

获取匹配点的坐标。

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

显示匹配点。数据中仍然包含几个离群值,但您可以看到旋转和缩放对匹配特征显示的影响。

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

Figure contains an axes object. The hidden axes object contains 4 objects of type image, line. One or more of the lines displays its values using only markers These objects represent matched points 1, matched points 2.

输入参数

全部折叠

特征集 1,指定为 binaryFeatures 对象、M1×N 矩阵,或 Point Feature Types 中描述的点特征对象之一。该矩阵包含 M1 个特征,而 N 则对应每个特征向量的长度。您可以使用 extractFeatures 函数,结合快速视网膜关键点 (FREAK)、定向 FAST 和旋转 BRIEF (ORB) 或二进制稳健不变可扩展关键点 (BRISK) 描述子方法,获取 binaryFeatures 对象。

特征集 2,指定为 binaryFeatures 对象、M2×N 矩阵,或 Point Feature Types 中描述的点特征对象之一。该矩阵包含 M2 个特征,而 N 则对应每个特征向量的长度。您可以使用 extractFeatures 函数,结合快速视网膜关键点 (FREAK)、定向 FAST 和旋转 BRIEF (ORB) 或二进制稳健不变可扩展关键点 (BRISK) 描述子方法,获取 binaryFeatures 对象。

名称-值参数

全部折叠

将可选参量对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但对各个参量对组的顺序没有要求。

如果使用的是 R2021a 之前的版本,请使用逗号分隔每个名称和值,并用引号将 Name 引起来。

示例: Method="Exhaustive" 将匹配方法设置为 Exhaustive

匹配方法,指定为 "Exhaustive""Approximate"。该方法规定了如何查找 features1features2 之间的最近邻。当两个特征向量之间的距离小于由 MatchThreshold 参数设定的阈值时,即视为匹配。

"Exhaustive"

计算 features1features2 中特征向量之间的成对距离。

"Approximate"

使用一种高效的近似最近邻搜索算法。对于大型特征集,请使用此方法。[3]

匹配阈值,指定为 (0,100] 范围内的标量百分比值。默认值对于二进制特征向量设置为 10.0,对于非二进制特征向量则设置为 1.0。您可以使用匹配阈值来筛选最匹配的结果。阈值表示与完全匹配之间距离的百分比。

当两个特征向量之间的距离小于 MatchThreshold 设定的阈值时,即视为匹配。当特征之间的距离大于 MatchThreshold 的值时,该函数会拒绝匹配。增加该值以返回更多匹配结果。

作为 binaryFeatures 对象的输入通常需要更大的匹配值。在提取 FREAK、ORB 或 BRISK 描述符时,extractFeatures 函数会返回 binaryFeatures 对象。

比率阈值,指定为 (0,1] 范围内的标量比率值。使用最大比例来过滤模棱两可的匹配结果。增加此值可返回更多匹配结果。

特征匹配度量,指定为 "SAD""SSD"

"SAD"绝对差的和
"SSD"差的平方和

当输入要素集 features1features2 不是 binaryFeatures 对象时,此属性适用。当您将特征指定为 binaryFeatures 对象时,该函数会使用汉明距离来计算相似度度量。

唯一匹配项,指定为 falsetrue。将此值设置为 true,以仅返回 features1features2 之间的唯一匹配项。

当您将 Unique 设置为 false 时,该函数会返回 features1features2 之间的所有匹配项。features1 中的多个特征可以与 features2 中的一个特征匹配。

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

当将 Unique 设置为 true 时,该函数会执行正向-反向匹配以选出唯一匹配项。在将 features1features2 进行匹配后,它会将 features2features1 进行匹配,并保留最佳匹配结果。

输出参量

全部折叠

两个输入特征集之间对应特征的索引,以一个 P 行 × 2 列、包含 P 个索引的矩阵形式返回。每对索引都对应于 features1features2 输入之间的一个匹配特征。第一个元素用于在 features1 中定位该特征。第二个元素在 features2 中索引匹配的特征。

匹配特征之间的距离,以 p×1 向量的形式返回。距离的值取决于所选的度量标准。i 中的第 matchmetric 个元素对应于输出矩阵 indexPairs 中的第 i 行。当 Metric 被设置为 SADSSD 时,特征向量会在计算前被归一化为单位向量。

度量范围完美匹配值
SAD[0, 2*sqrt(size(features1, 2))] 0
SSD[0,4]0
Hamming[0, features1.NumBits]0

参考

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

扩展功能

全部展开

版本历史记录

在 R2011a 中推出