如何衡量两个图像之间的相似度? [英] How can I measure the similarity between two images?

查看:38
本文介绍了如何衡量两个图像之间的相似度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个应用程序(可能是网页)的屏幕截图与之前截取的屏幕截图进行比较,以确定该应用程序是否正确显示自身.我不想要精确匹配比较,因为方面可能略有不同(在 Web 应用程序的情况下,根据浏览器的不同,某些元素可能位于略有不同的位置).它应该可以衡量屏幕截图的相似程度.

I would like to compare a screenshot of one application (could be a Web page) with a previously taken screenshot to determine whether the application is displaying itself correctly. I don't want an exact match comparison, because the aspect could be slightly different (in the case of a Web app, depending on the browser, some element could be at a slightly different location). It should give a measure of how similar are the screenshots.

有没有已经这样做的库/工具?您将如何实施?

Is there a library / tool that already does that? How would you implement it?

推荐答案

这完全取决于您希望算法的智能程度.

This depends entirely on how smart you want the algorithm to be.

例如,这里有一些问题:

For instance, here are some issues:

  • 裁剪图像与未裁剪图像
  • 添加了文本的图像与未添加文本的图像
  • 镜像图像

我见过的最简单和最简单的算法就是对每个图像执行以下步骤:

The easiest and simplest algorithm I've seen for this is just to do the following steps to each image:

  1. 缩放到较小的尺寸,例如 64x64 或 32x32,忽略纵横比,使用组合缩放算法而不是最近的像素
  2. 缩放颜色范围,使最暗的是黑色,最亮的是白色
  3. 旋转并翻转图像,使最亮的颜色在左上角,然后右上角的下一个颜色更深,左下角的下一个颜色更深(当然尽可能)

编辑 组合缩放算法是一种将 10 个像素缩小为 1 个的算法,该算法使用一个函数来获取所有这 10 个像素的颜色并将它们组合起来成一.可以使用平均算法、平均值算法或更复杂的算法(如双三次样条)来完成.

Edit A combining scaling algorithm is one that when scaling 10 pixels down to one will do it using a function that takes the color of all those 10 pixels and combines them into one. Can be done with algorithms like averaging, mean-value, or more complex ones like bicubic splines.

然后逐个像素地计算两幅图像之间的平均距离.

Then calculate the mean distance pixel-by-pixel between the two images.

要在数据库中查找可能的匹配项,将像素颜色作为单独的列存储在数据库中,索引一堆(但不是全部,除非您使用非常小的图像),然后执行使用每个像素值的范围,即.小图像中的像素在您要查找的图像的 -5 到 +5 之间的每个图像.

To look up a possible match in a database, store the pixel colors as individual columns in the database, index a bunch of them (but not all, unless you use a very small image), and do a query that uses a range for each pixel value, ie. every image where the pixel in the small image is between -5 and +5 of the image you want to look up.

这很容易实现,运行起来也相当快,但当然不会处理最高级的差异.为此,您需要更高级的算法.

This is easy to implement, and fairly fast to run, but of course won't handle most advanced differences. For that you need much more advanced algorithms.

这篇关于如何衡量两个图像之间的相似度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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