比较图像相似度的简单快速方法 [英] Simple and fast method to compare images for similarity

查看:10
本文介绍了比较图像相似度的简单快速方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种简单快速的方法来比较两张图片的相似度.IE.如果它们包含完全相同的东西但可能有一些稍微不同的背景并且可能会移动/调整几个像素,我想获得一个高值.

(更具体地说,如果重要的话:一张图片是图标,另一张图片是屏幕截图的子区域,我想知道该子区域是否正是图标.)

我手头有 OpenCV,但我还是不太习惯.

到目前为止,我想到了一种可能性:将两张图片分成 10x10 的单元格,并为这 100 个单元格中的每一个单元格比较颜色直方图.然后我可以设置一些虚构的阈值,如果我得到的值高于该阈值,我认为它们是相似的.

我还没有尝试过它的效果如何,但我想它已经足够好了.这些图像已经非常相似(在我的用例中),所以我可以使用相当高的阈值.

我想还有很多其他可能的解决方案或多或少会起作用(因为任务本身非常简单,因为我只想检测它们是否非常相似).你有什么建议?

<小时>

关于从图像中获取签名/指纹/哈希有几个非常相关/相似的问题:

另外,我偶然发现了这些具有获取指纹功能的实现:

关于感知图像哈希的一些讨论:这里

<小时>

有点题外话:有很多方法可以创建音频指纹.MusicBrainz,一个提供基于指纹的歌曲查找的网络服务,有一个 在他们的 wiki 中有很好的概述.他们现在正在使用 AcoustID.这是为了查找精确(或大部分精确)匹配.要查找相似的匹配项(或者如果您只有一些片段或高噪音),请查看 Echoprint.一个相关的 SO 问题是这里.所以这似乎解决了音频问题.所有这些解决方案都非常有效.

关于模糊搜索的一般性问题是这里.例如.有 locality-sensitive hashing最近邻搜索.

解决方案

屏幕截图或图标可以变形(缩放、旋转、倾斜...)吗?有很多方法可以帮助你:

  • 简单欧式距离,如 @carlosdc 所述(不适用于转换后的图像,您需要一个阈值).
  • (标准化)互相关 - 一个简单的指标您可以使用它来比较图像区域.它比简单的欧几里得距离更稳健,但不适用于转换后的图像,您将再次需要一个阈值.
  • 直方图比较 - 如果您使用归一化直方图,此方法效果很好,并且不受仿射变换的影响.问题在于确定正确的阈值.它对颜色变化(亮度、对比度等)也非常敏感.您可以将其与前两者结合使用.
  • 突出点/区域的检测器 - 例如 MSER(最大稳定极值区域))SURFSIFT.这些是非常强大的算法,对于您的简单任务来说它们可能太复杂了.好消息是您不必拥有一个只有一个图标的确切区域,这些检测器功能强大,可以找到正确的匹配项.本文对这些方法进行了很好的评估:局部不变特征检测器:一项调查.

其中大部分已经在 OpenCV 中实现 - 例如参见 cvMatchTemplate 方法(使用直方图匹配):http://dasl.mem.drexel.edu/~noahKuntz/openCVTut6.html.突出点/区域检测器也可用 - 请参阅 OpenCV 特征检测.p>

I need a simple and fast way to compare two images for similarity. I.e. I want to get a high value if they contain exactly the same thing but may have some slightly different background and may be moved / resized by a few pixel.

(More concrete, if that matters: The one picture is an icon and the other picture is a subarea of a screenshot and I want to know if that subarea is exactly the icon or not.)

I have OpenCV at hand but I am still not that used to it.

One possibility I thought about so far: Divide both pictures into 10x10 cells and for each of those 100 cells, compare the color histogram. Then I can set some made up threshold value and if the value I get is above that threshold, I assume that they are similar.

I haven't tried it yet how well that works but I guess it would be good enough. The images are already pretty much similar (in my use case), so I can use a pretty high threshold value.

I guess there are dozens of other possible solutions for this which would work more or less (as the task itself is quite simple as I only want to detect similarity if they are really very similar). What would you suggest?


There are a few very related / similar questions about obtaining a signature/fingerprint/hash from an image:

Also, I stumbled upon these implementations which have such functions to obtain a fingerprint:

Some discussions about perceptual image hashes: here


A bit offtopic: There exists many methods to create audio fingerprints. MusicBrainz, a web-service which provides fingerprint-based lookup for songs, has a good overview in their wiki. They are using AcoustID now. This is for finding exact (or mostly exact) matches. For finding similar matches (or if you only have some snippets or high noise), take a look at Echoprint. A related SO question is here. So it seems like this is solved for audio. All these solutions work quite good.

A somewhat more generic question about fuzzy search in general is here. E.g. there is locality-sensitive hashing and nearest neighbor search.

解决方案

Can the screenshot or icon be transformed (scaled, rotated, skewed ...)? There are quite a few methods on top of my head that could possibly help you:

  • Simple euclidean distance as mentioned by @carlosdc (doesn't work with transformed images and you need a threshold).
  • (Normalized) Cross Correlation - a simple metrics which you can use for comparison of image areas. It's more robust than the simple euclidean distance but doesn't work on transformed images and you will again need a threshold.
  • Histogram comparison - if you use normalized histograms, this method works well and is not affected by affine transforms. The problem is determining the correct threshold. It is also very sensitive to color changes (brightness, contrast etc.). You can combine it with the previous two.
  • Detectors of salient points/areas - such as MSER (Maximally Stable Extremal Regions), SURF or SIFT. These are very robust algorithms and they might be too complicated for your simple task. Good thing is that you do not have to have an exact area with only one icon, these detectors are powerful enough to find the right match. A nice evaluation of these methods is in this paper: Local invariant feature detectors: a survey.

Most of these are already implemented in OpenCV - see for example the cvMatchTemplate method (uses histogram matching): http://dasl.mem.drexel.edu/~noahKuntz/openCVTut6.html. The salient point/area detectors are also available - see OpenCV Feature Detection.

这篇关于比较图像相似度的简单快速方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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