图像比较算法 [英] Image comparison algorithm

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

问题描述

我想将图片彼此比较,以了解它们是否不同。首先,我试图对RGB值进行皮尔逊相关,除非图片是一个位元移位,这也很好。所以如果一个有100%相同的图像,但一个有点移动,我得到一个不良的相关值。



任何建议更好的算法?



BTW,我在谈论比较一千个图片...



编辑:
这是我的照片(微观)示例:



im1:





im2:



>



im3:



im1和im2是相同的但有点移位/ cutted,im3应该被识别为完全不同...



编辑:
问题已解决,Peter Hansen的建议!工作非常好!感谢所有的答案!一些结果可以在这里找到
http:// labtools。 ipk-gatersleben.de/image%20comparison/image%20comparision.pdf

解决方案

A <一年前曾被问过一个href =http://stackoverflow.com/questions/189943/how-can-i-quantify-difference-between-two-images>类似问题,并有许多回应,包括一个关于像素化图像,我将建议作为至少一个资格预审步骤(因为它会很快地排除非常不相似的图像)。





这里有一个实现使用Scipy的一些想法,使用您的上述三个图像分别保存为im1.jpg,im2.jpg,im3.jpg)。最后的输出显示im1与自身比较,作为基线,然后每个图像与其他图像比较。

 > > import spipy as sp 
>>>>来自scipy.misc import imread
>>>>从scipy.signal.signaltools导入correlate2d为c2d
>>>
>>>> def get(i):
...#获取JPG图像作为Scipy数组,RGB(3层)
... data = imread('im%s.jpg'%i)
...#使用W3C亮度计算转换为灰度计算
... data = sp.inner(data,[299,587,114])/ 1000.0
...# ://en.wikipedia.org/wiki/Cross-correlation
... return(data - data.mean())/ data.std()
...
> >> im1 = get(1)
>>>> im2 = get(2)
>>>> im3 = get(3)
>>>> im1.shape
(105,401)
>>>> im2.shape
(109,373)
>>>> im3.shape
(121,457)
>>>> c11 = c2d(im1,im1,mode ='same')#baseline
>>>> c12 = c2d(im1,im2,mode ='same')
>>>> c13 = c2d(im1,im3,mode ='same')
>>>> c23 = c2d(im2,im3,mode ='same')
>>> c11.max(),c12.max(),c13.max(),c23.max()
(42105.00000000259,39898.103896795357,16482.883608327804,15873.465425120798)


运行时间长,在我的机器上长达几分钟,您可能需要尝试其他图片来查看此效果的效果如何,以及如何改善。 。我会尝试一些预过滤,以避免浪费时间比较非常不相似的图像,也许与比较jpg文件大小技巧在对另一个问题的答复或像素化。事实上,你有不同大小的图像使事情复杂化,但你没有给出足够的信息,关于屠宰的程度可能期望,所以很难给出一个具体的答案,考虑到这一点。


I'm trying to compare images to each other to find out whether they are different. First I tried to make a Pearson correleation of the RGB values, which works also quite good unless the pictures are a litte bit shifted. So if a have a 100% identical images but one is a little bit moved, I get a bad correlation value.

Any suggestions for a better algorithm?

BTW, I'm talking about to compare thousand of imgages...

Edit: Here is an example of my pictures (microscopic):

im1:

im2:

im3:

im1 and im2 are the same but a little bit shifted/cutted, im3 should be recognized as completly different...

Edit: Problem is solved with the suggestions of Peter Hansen! Works very well! Thanks to all answers! Some results can be found here http://labtools.ipk-gatersleben.de/image%20comparison/image%20comparision.pdf

解决方案

A similar question was asked a year ago and has numerous responses, including one regarding pixelizing the images, which I was going to suggest as at least a pre-qualification step (as it would exclude very non-similar images quite quickly).

There are also links there to still-earlier questions which have even more references and good answers.

Here's an implementation using some of the ideas with Scipy, using your above three images (saved as im1.jpg, im2.jpg, im3.jpg, respectively). The final output shows im1 compared with itself, as a baseline, and then each image compared with the others.

>>> import scipy as sp
>>> from scipy.misc import imread
>>> from scipy.signal.signaltools import correlate2d as c2d
>>>
>>> def get(i):
...     # get JPG image as Scipy array, RGB (3 layer)
...     data = imread('im%s.jpg' % i)
...     # convert to grey-scale using W3C luminance calc
...     data = sp.inner(data, [299, 587, 114]) / 1000.0
...     # normalize per http://en.wikipedia.org/wiki/Cross-correlation
...     return (data - data.mean()) / data.std()
...
>>> im1 = get(1)
>>> im2 = get(2)
>>> im3 = get(3)
>>> im1.shape
(105, 401)
>>> im2.shape
(109, 373)
>>> im3.shape
(121, 457)
>>> c11 = c2d(im1, im1, mode='same')  # baseline
>>> c12 = c2d(im1, im2, mode='same')
>>> c13 = c2d(im1, im3, mode='same')
>>> c23 = c2d(im2, im3, mode='same')
>>> c11.max(), c12.max(), c13.max(), c23.max()
(42105.00000000259, 39898.103896795357, 16482.883608327804, 15873.465425120798)

So note that im1 compared with itself gives a score of 42105, im2 compared with im1 is not far off that, but im3 compared with either of the others gives well under half that value. You'd have to experiment with other images to see how well this might perform and how you might improve it.

Run time is long... several minutes on my machine. I would try some pre-filtering to avoid wasting time comparing very dissimilar images, maybe with the "compare jpg file size" trick mentioned in responses to the other question, or with pixelization. The fact that you have images of different sizes complicates things, but you didn't give enough information about the extent of butchering one might expect, so it's hard to give a specific answer that takes that into account.

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

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