与特征点检测相关的像素索引

pixels' indices related to Features points detection

下面的代码展示了两张图片对应的特征点。我怎样才能得到这个点的像素索引?例如,我想获取位于第一张图像中的第一个特征点的像素索引(行和列)。

I1=rgb2gray(imread('peau.jpg'));   
I2=imresize(imrotate(I1,-20),1.2);
points1=detectSURFFeatures(I1);
points2=detectSURFFeatures(I2);   
[f1,vpts1] = extractFeatures(I1, points1);     
[f2,vpts2] = extractFeatures(I2, points2);    
[indexPairs,cv] = matchFeatures(f1, f2) ;      
matchedPoints1 = vpts1(indexPairs(:, 1));       
matchedPoints2 = vpts2(indexPairs(:, 2));      
figure; ax = axes;      
showMatchedFeatures(I1,I2,matchedPoints1,matchedPoints2);      
legend(ax,'Matched points 1','Matched points 2');  

vpts1vpts2 分别为您提供在第一张图像和第二张图像之间检测到的特征点。 indexPairs returns 一个 N x 2 矩阵,其中每一行为您提供相应图像之间匹配的两个特征。每行的第一个元素为您提供 index,其中 vpts1 中的特征与 vpts2 中的相应特征相匹配,这是该行的第二个元素。

如果你想要每个特征的实际像素位置,你需要分别访问vpts1vpts2Location字段,所以:

loc1 = vpts1.Location;
loc2 = vpts2.Location;

每个都会给你一个 N x 2 矩阵,其中第一列表示 x 或水平坐标,而第二列表示 y 或垂直坐标。现在,要获取两个图像之间匹配的第一个特征的像素坐标,只需执行以下操作:

pt1_loc = loc1(indexPairs(1,1),:);
pt2_loc = loc2(indexPairs(1,2),:);

indexPairs(1,1)indexPairs(1,2) 确定了第一张和第二张图像之间匹配的特征的相应索引,因此您可以使用这些索引来索引两张图像本身的位置数组。