compare python_比较两个图像python / linux的方式(Compare two images the python/linux way)

比较两个图像python / linux的方式(Compare two images the python/linux way)

试图解决防止重复图像上传的问题。

我有两个JPG。 看着它们,我可以看到它们实际上是相同的。 但由于某些原因,它们具有不同的文件大小(一个是从备份中提取的,另一个是另一个上传文件),因此它们具有不同的md5校验和。

我如何有效和自信地比较两幅图像,就像人类能够看到它们明显相同一样?

更新

我写了这个脚本:

import math, operator

from PIL import Image

def compare(file1, file2):

image1 = Image.open(file1)

image2 = Image.open(file2)

h1 = image1.histogram()

h2 = image2.histogram()

rms = math.sqrt(reduce(operator.add,

map(lambda a,b: (a-b)**2, h1, h2))/len(h1))

return rms

if __name__=='__main__':

import sys

file1, file2 = sys.argv[1:]

print compare(file1, file2)

然后我下载了两张视觉相同的图像并运行脚本。 输出:

58.9830484122

任何人都可以告诉我什么是合适的截止点?

更新II

a.jpg和b.jpg的区别在于第二个已经保存了PIL:

b=Image.open('a.jpg')

b.save(open('b.jpg','wb'))

这显然适用于一些非常非常轻质的修改。 现在我已经解决了我的问题,通过将相同的PIL保存到正在上传的文件中,而无需执行任何操作,现在它可以工作!

Trying to solve a problem of preventing duplicate images to be uploaded.

I have two JPGs. Looking at them I can see that they are in fact identical. But fo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值