如何使用SIFT算法计算两幅图像的相似程度? [英] How to use SIFT algorithm to compute how similar two images are?

查看:76
本文介绍了如何使用SIFT算法计算两幅图像的相似程度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 SIFT 实现 Andrea Vedaldi,计算两个相似图像的筛选描述符(第二张图片实际上是同一物体从不同角度放大的图片).

现在我不知道如何比较描述符以判断图像的相似程度?

我知道除非您之前实际玩过这类事情,否则这个问题是无法回答的,但我认为以前做过这件事的人可能知道这一点,所以我发布了这个问题.

我为生成描述符所做的小事:

<代码>>>i=imread('p1.jpg');>>j=imread('p2.jpg');>>i=rgb2gray(i);>>j=rgb2gray(j);>>[a, b]=sift(i);% a 有帧,b 有描述符>>[c, d]=sift(j);

解决方案

首先,你不是应该使用 vl_sift 而不是 sift 吗?

其次,您可以使用 SIFT 特征匹配来查找两个图像中的对应关系.这是一些示例代码:

 I = imread('p1.jpg');J = imread('p2.jpg');我 = 单(rgb2gray(我));% 建议转换为单身J = 单 (rgb2gray(J));% 在文档中[F1 D1] = vl_sift(I);[F2 D2] = vl_sift(J);% 其中 1.5 = NN2/NN1 的欧氏距离之比[比赛得分] = vl_ubcmatch(D1,D2,1.5);子图(1,2,1);imshow(uint8(I));坚持,稍等;plot(F1(1,matches(1,:)),F1(2,matches(1,:)),'b*');子图(1,2,2);imshow(uint8(J));坚持,稍等;plot(F2(1,matches(2,:)),F2(2,matches(2,:)),'r*');

vl_ubcmatch() 主要执行以下操作:

假设您在 F1 中有一个点 P 并且您想在 F2 中找到最佳"匹配.一种方法是将 F1 中 P 的描述符与 D2 中的所有描述符进行比较.通过比较,我的意思是找到欧几里得距离(或两个描述符的差异的 L2 范数).

然后,我在 F2 中找到两个点,比如说 U &V 分别与 P 有最低和第二低的距离(比如 Du 和 Dv).

这是 Lowe 推荐的:如果 Dv/Du >= 阈值(我在示例代码中使用了 1.5),那么这个匹配是可以接受的;否则,它被模糊匹配并作为对应被拒绝,我们不会将 F2 中的任何点与 P 匹配.本质上,如果最佳和次佳匹配之间存在很大差异,您可以期望这是一次高质量的匹配.

这很重要,因为图像中有很多模糊匹配的范围:想象一下匹配湖泊或具有多个窗户的建筑物中的点,描述符可能看起来非常相似,但对应关系显然是错误的.

您可以通过多种方式进行匹配……您可以使用 MATLAB 自己轻松完成,也可以使用 KD 树或近似最近数搜索(如 FLANN 已在 OpenCV.

另外,MATLAB 中有几个 kd-tree 实现..>

I have used the SIFT implementation of Andrea Vedaldi, to calculate the sift descriptors of two similar images (the second image is actually a zoomed in picture of the same object from a different angle).

Now I am not able to figure out how to compare the descriptors to tell how similar the images are?

I know that this question is not answerable unless you have actually played with these sort of things before, but I thought that somebody who has done this before might know this, so I posted the question.

the little I did to generate the descriptors:

>> i=imread('p1.jpg');
>> j=imread('p2.jpg');
>> i=rgb2gray(i);
>> j=rgb2gray(j);
>> [a, b]=sift(i);  % a has the frames and b has the descriptors
>> [c, d]=sift(j);

解决方案

First, aren't you supposed to be using vl_sift instead of sift?

Second, you can use SIFT feature matching to find correspondences in the two images. Here's some sample code:

    I = imread('p1.jpg');
    J = imread('p2.jpg');

    I = single(rgb2gray(I)); % Conversion to single is recommended
    J = single(rgb2gray(J)); % in the documentation

    [F1 D1] = vl_sift(I);
    [F2 D2] = vl_sift(J);

    % Where 1.5 = ratio between euclidean distance of NN2/NN1
    [matches score] = vl_ubcmatch(D1,D2,1.5); 

    subplot(1,2,1);
    imshow(uint8(I));
    hold on;
    plot(F1(1,matches(1,:)),F1(2,matches(1,:)),'b*');

    subplot(1,2,2);
    imshow(uint8(J));
    hold on;
    plot(F2(1,matches(2,:)),F2(2,matches(2,:)),'r*');

vl_ubcmatch() essentially does the following:

Suppose you have a point P in F1 and you want to find the "best" match in F2. One way to do that is to compare the descriptor of P in F1 to all the descriptors in D2. By compare, I mean find the Euclidean distance (or the L2-norm of the difference of the two descriptors).

Then, I find two points in F2, say U & V which have the lowest and second-lowest distance (say, Du and Dv) from P respectively.

Here's what Lowe recommended: if Dv/Du >= threshold (I used 1.5 in the sample code), then this match is acceptable; otherwise, it's ambiguously matched and is rejected as a correspondence and we don't match any point in F2 to P. Essentially, if there's a big difference between the best and second-best matches, you can expect this to be a quality match.

This is important since there's a lot of scope for ambiguous matches in an image: imagine matching points in a lake or a building with several windows, the descriptors can look very similar but the correspondence is obviously wrong.

You can do the matching in any number of ways .. you can do it yourself very easily with MATLAB or you can speed it up by using a KD-tree or an approximate nearest number search like FLANN which has been implemented in OpenCV.

EDIT: Also, there are several kd-tree implementations in MATLAB.

这篇关于如何使用SIFT算法计算两幅图像的相似程度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆