如何使用SIFT算法计算两幅图像的相似度?
我使用了 SIFT 实现 Andrea Vedaldi,计算两个相似图像的 sift 描述符(第二个图像是实际上是同一物体从不同角度的放大图片)。
现在我无法弄清楚如何比较描述符来判断图像的相似程度?
我知道这个问题是无法回答的,除非你以前确实玩过这类东西,但我认为以前做过这个的人可能知道这一点,所以我发布了这个问题。
我为生成描述符所做的一点工作:
>> 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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
首先,你不是应该使用 vl_sift 而不是 sift 吗?
其次,您可以使用 SIFT 特征匹配来查找两幅图像中的对应关系。下面是一些示例代码:
vl_ubcmatch() 本质上执行以下操作:
假设 F1 中有一个点 P,并且您想在 F2 中找到“最佳”匹配。一种方法是将 F1 中 P 的描述符与 D2 中的所有描述符进行比较。通过比较,我的意思是找到欧几里得距离(或两个描述符之差的 L2 范数)。
然后,我在 F2 中找到两个点,比如 U 和 U 。 V 分别与 P 具有最小和第二小的距离(例如 Du 和 Dv)。
Lowe 的建议是这样的:如果 Dv/Du >= 阈值(我在示例代码中使用了 1.5),那么这个匹配是可以接受的;否则,它的匹配不明确,并且作为对应被拒绝,并且我们不会将 F2 中的任何点与 P 相匹配。本质上,如果最佳匹配和次优匹配之间存在很大差异,则可以预期这是一个质量匹配。
这很重要,因为图像中存在很大的模糊匹配范围:想象一下湖泊或具有多个窗户的建筑物中的匹配点,描述符可能看起来非常相似,但对应关系显然是错误的。
您可以通过多种方式进行匹配..您可以使用 MATLAB 自己轻松完成匹配,或者您可以通过使用 KD 树或近似最近数字搜索(如 FLANN 已在 OpenCV。
编辑:另外,MATLAB 中有几种 kd-tree 实现。
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:
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.
您应该阅读 David Lowe 的论文,其中讨论了如何准确地做到这一点那。如果您想比较完全相同对象的图像,这应该足够了。如果您想匹配同一类别的不同对象(例如汽车或飞机)的图像,您可能需要查看 金字塔匹配内核,作者:Grauman 和 Darrell。
You should read David Lowe's paper, which talks about how to do exactly that. It should be sufficient, if you want to compare images of the exact same object. If you want to match images of different objects of the same category (e.g. cars or airplanes) you may want to look at the Pyramid Match Kernel by Grauman and Darrell.
尝试将第一幅图像中的每个描述符与位于附近的第二幅图像中的描述符进行比较(使用欧几里德距离)。因此,您可以根据第一个图像中的每个描述符与第二个图像中最相似的邻居描述符之间的相似程度为该描述符分配一个分数。所有这些分数的统计测量(总和、平均值、离散度、平均误差等)可以让您估计图像的相似程度。尝试邻近区域大小和统计测量的不同组合,以获得最佳答案。
Try to compare each descriptor from the first image with descriptors from the second one situated in a close vicinity (using the Euclidean distance). Thus, you assign a score to each descriptor from the first image based on the degree of similarity between it and the most similar neighbor descriptor from the second image. A statistical measure (sum, mean, dispersion, mean error, etc) of all these scores gives you an estimate of how similar the images are. Experiment with different combinations of vicinity size and statistical measure to give you the best answer.
如果您只想将缩放和旋转的图像与已知的旋转中心进行比较,您可以在对数极坐标中使用相位相关。通过峰值的清晰度和相位相关的直方图,您可以判断图像的接近程度。您还可以对傅里叶系数的绝对值使用欧几里德距离。
如果你想比较 SIFT 描述符,除了欧几里德距离之外,你还可以使用“扩散距离”——在逐渐更粗糙的尺度上获取描述符并将它们与原始描述符连接起来。这样,“大规模”特征相似性就会有更大的权重。
If you want just compare zoomed and rotated image with known center of rotation you can use phase correlation in log-polar coordinates. By sharpness of peak and histogram of phase correlation you can judge how close images are. You can also use euclidean distance on absolute value of Fourier coefficients.
If you want compare SIFT descriptor, beside euclidean distance you can also use "diffuse distance" - getting descriptor on progressively more rough scale and concatenating them with original descriptor. That way "large scale" feature similarity would have more weight.
如果你想在图像之间进行匹配,你应该使用 vl_ubcmatch (如果你还没有使用它)。您可以解释输出的“分数”以查看特征的接近程度。这表示两个匹配特征描述符之间的欧氏距离的平方。您还可以改变最佳匹配和第二最佳匹配之间的阈值作为输入。
If you want to do matching between the images, you should use vl_ubcmatch (in case you have not used it). You can interpret the output 'scores' to see how close the features are. This represents the square of euclidean distance between the two matching feature descriptor. You can also vary the threshold between Best match and 2nd best match as input.