使用Pillow来自同一来源的不同图像数据 [英] Different image data from the same source with Pillow

查看:127
本文介绍了使用Pillow来自同一来源的不同图像数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在移动一个脚本,该脚本从Windows主机向Debian主机创建图像中的本地敏感哈希.
我的问题是Pillow在两个平台上从同一源图像返回不同的图像数据.
我只观察到jpeg的这种行为.
测试用例:

I am currently moving a script which creates local sensitive hashes from images from a windows host to a debian one.
My problem is Pillow returns different image data from the same source image on both platforms.
I only observed this behavior for jpegs.
Test case:

from PIL import Image
import md5
import urllib2 
from cStringIO import StringIO
urls = ("https://i.imgur.com/Mx6NQwM.jpg","https://i.imgur.com/MN1TKu5.png")
print("VERSION %s" % Image.VERSION)
for url in urls:
    response = urllib2.urlopen(url).read()
    img = Image.open(StringIO(response)).convert("RGB")
    img_md5 = "".join("".join(map(chr, x)) for x in img.getdata())
    print("URL: %s" % url)
    print("Plain md5:\t%s" % md5.new(response.read()).hexdigest())
    print("Image md5:\t%s" % md5.new(img_md5).hexdigest())

应在两个系统上返回相同的md5哈希值. 我的结果:
Windows 7:

Should return the same md5 hashes on both systems. My results:
Windows 7:

VERSION 1.1.7
URL: https://i.imgur.com/Mx6NQwM.jpg
Plain md5:  4aacd5b92575ffca6d0ab884f95cc1f9
Image md5:  10eaf568f4d9d33c722ea702fc4d1025
URL: https://i.imgur.com/MN1TKu5.png
Plain md5:  d05e6dc1311339b806e5998f15fc818c
Image md5:  38fc986c5cd9605038ee627b11687344

Debian jessie:

VERSION 1.1.7
URL: https://i.imgur.com/Mx6NQwM.jpg
Plain md5:      4aacd5b92575ffca6d0ab884f95cc1f9
Image md5:      7347c6286f4d917649d967a5025e392e
URL: https://i.imgur.com/MN1TKu5.png
Plain md5:      d05e6dc1311339b806e5998f15fc818c
Image md5:      38fc986c5cd9605038ee627b11687344

LSH有点相似,但又有很大的区别,以至于出现问题.
两个系统上的枕头版本均为2.9.0.

The LSHs are somewhat similar, but different enough for it to be problematic.
The pillow version on both systems is 2.9.0.

是否可以像在Windows上一样在debian系统上获得相同的像素值?
通常:有人知道为什么会这样吗?

Is there some way to get the same pixel value on the debian system like i get on the windows one ?
And in general: Does someone know why this is happening ?

推荐答案

我解决"了我的问题.
我在Windows主机上意外安装了PILPillow.
看起来它选择使用PIL版本.
在debian机器上使用PIL后,两台机器上的结果也相同.
通常,将PIL端升级为使用Pillow是更明智的选择,但就我而言,我需要生成与PIL版本完全相同的哈希.

I "solved" my problem.
I had PIL and Pillow installed on the windows host by accident.
It looks like it choose to use the PIL version.
After using PIL on the debian machine, too the results are the same on both machines.
Generally it would be wiser to upgrade the PIL side to use Pillow, but in my case i need to generate the exact same hashes like i did with the PIL version.

故事的情节: PILPillow在加载相同图像时可能返回不同的图像数据.

Morale of the story: PIL and Pillow may return different image data when loading the same images.

这篇关于使用Pillow来自同一来源的不同图像数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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