7

我已经检查了像 Phasher 这样的方法来获得类似的图像。基本上将图像大小调整为 8x8,灰度,获取平均像素并创建每个像素的二进制哈希,比较它是否高于或低于平均像素。

这种方法在这里解释得很好: http ://hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html

工作示例: - 桌子上计算机的图像 1 - 图像 2,相同,但带有硬币

在此处输入图像描述

这是可行的,因为使用非常缩小的灰度图像的散列,它们两者几乎相同,甚至相同。因此,当 90% 以上的像素相同(在同一个地方!)时,您可以得出结论它们是相似的

我的问题是从相同的角度但不同的角度拍摄的图像,例如:

在此处输入图像描述

在这种情况下,生成的哈希“指纹”相互偏移,以至于我们无法逐位比较哈希,这将是非常不同的。

像素是“相似的”,但它们不在同一个地方,因为在这种情况下,天空更多,房屋“开始”比第一个更低。

所以哈希比较结果是“它们是不同的图像”。

可能的解决方案:

我正在考虑为第一个图像创建一个更大的散列,然后为第二个图像获取 10 个随机“子散列”,并尝试查看 10 个子散列是否在第一个大散列的“某个地方”(如果一个子字符串包含在另一个更大的字符串中)。

我认为这里的问题是处理数千张图像时的 CPU/时间,因为您必须将 1 张图像与 1000 张图像进行比较,并且在每张图像中,将 10 个子哈希与一个大哈希进行比较。

其他解决方案?;-)

4

2 回答 2

7

One option is to detect a set of "interesting" points for each image and store that alongside your hash. It's somewhat similar to the solution you suggested.

We want those points be unlikely to vary between images like yours that have shifts in perspective. These lecture slides give a good overview of how to find points like that with fairly straightforward linear algebra. I'm using Mathematica because it has built in functions for a lot of this stuff. ImageKeypoints does what we want here.

After we have our interesting points we need to find which ones match between the images we're comparing. If your images are very similar, like the ones in your examples, you could probably just take an 8x8 greyscale image for each interesting point and compare each from one image with the ones for the nearby interesting points on the other image. I think you could use your existing algorithm.

If you wanted to use a more advanced algorithm like SIFT you'd need to have a look at ImageKeypoint's properties like scale and orientation.

The ImageKeypoints documentation has this example you can use to get a small piece of the image for each interesting point (it uses the scale property instead of a fixed size):

MapThread[ImageTrim[img, {#1}, 2.5 #2] &, 
 Transpose@
  ImageKeypoints[img, {"Position", "Scale"}, 
   "KeypointStrength" -> .001]]

Finding a certain number of matching points might be enough to say that the images are similar, but if not you can use something like RANSAC to figure out the transformation you need to align your hash images (the 8x8 images you're already able to generate) enough that your existing algorithm works.

I should point out that Mathematica has ImageCorrespondingPoints, which does all of this stuff (using ImageKeypoints) much better. But I don't know how you could have it cache the intermediate results so that scales for what you're trying to do. You might want to look into its ability to constrain matching points to a perspective transform, though.

Here's a plot of the matching points for your example images to give you an idea of what parts end up matching:

matching points

So you can precalculate the interesting points for your database of images, and the greyscale hashes for each point. You'll have to compare several hash images for each image in your database, rather than just two, but it will scale to within a constant factor of your current algorithm.

于 2014-06-04T19:27:39.020 回答
0

如果哈希不匹配,您可以尝试一个上限,比较 8x8 网格中有多少像素匹配。也许您可以尝试匹配照片马赛克中的颜色:照片马赛克算法。如何在给定基本图像和瓷砖列表的情况下创建马赛克照片?.

于 2014-05-30T08:50:18.313 回答