PIL /枕头解码ICC配置文件信息 [英] PIL/Pillow decode icc profile information
问题描述
我对解码/解析用PIL提取的ICC配置文件信息感到困惑。
I am stuck with decoding/parsing ICC-profile information extracted with PIL.
在包含 Adobe RGB(1998)配置文件的测试图像下面。 / p>
Below a test image that contains the "Adobe RGB (1998)" profile.
# download the test image:
wget http://i.stack.imgur.com/62AHB.jpg
-
from PIL import Image
path = '62AHB.jpg'
icc = Image.open(path).info.get('icc_profile')
到目前为止很好-但我找不到处理返回的ICC信息的方法。
So far so good - but I could not find a way to handle returned ICC information.
上面的示例将返回:
'\x00\x00\x020ADBE\x02\x10\x00\x00mntrRGB XYZ\x07\xcf\x00\x06\x00\x03\x00\x00\x00\x00\x00\x00acspAPPL\x00\x00\x00\x00none\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\xf6\xd6\x00\x01\x00\x00\x00\x00\xd3-ADBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ncprt\x00\x00\x00\xfc\x00\x00\x002desc\x00\x00\x010\x00\x00\x00kwtpt\x00\x00\x01\x9c\x00\x00\x00\x14bkpt\x00\x00\x01\xb0\x00\x00\x00\x14rTRC\x00\x00\x01\xc4\x00\x00\x00\x0egTRC\x00\x00\x01\xd4\x00\x00\x00\x0ebTRC\x00\x00\x01\xe4\x00\x00\x00\x0erXYZ\x00\x00\x01\xf4\x00\x00\x00\x14gXYZ\x00\x00\x02\x08\x00\x00\x00\x14bXYZ\x00\x00\x02\x1c\x00\x00\x00\x14text\x00\x00\x00\x00Copyright 1999 Adobe Systems Incorporated\x00\x00\x00desc\x00\x00\x00\x00\x00\x00\x00\x11Adobe RGB (1998)\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00XYZ \x00\x00\x00\x00\x00\x00\xf3Q\x00\x01\x00\x00\x00\x01\x16\xccXYZ \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00curv\x00\x00\x00\x00\x00\x00\x00\x01\x023\x00\x00XYZ \x00\x00\x00\x00\x00\x00\x9c\x18\x00\x00O\xa5\x00\x00\x04\xfcXYZ \x00\x00\x00\x00\x00\x004\x8d\x00\x00\xa0,\x00\x00\x0f\x95XYZ \x00\x00\x00\x00\x00\x00&1\x00\x00\x10/\x00\x00\xbe\x9c'
如何解码此信息?
里面似乎有一些键数据。在这种情况下,我基本上只需要 desc 的值,即 Adobe RGB(1998) 。
There seem to be some keys inside the data. I basically would just need the value for "desc" which is "Adobe RGB (1998)" in that case.
有什么想法吗?期待您的输入:)!
Any ideas? Looking forward for your inputs :) !
推荐答案
我也是为那些来这里搜索有关如何在Python中处理ICC颜色配置文件信息的人编写的。
I'm writing this also for people that came here searching for information on how to process ICC color profile information in Python.
Python原始PIL库的枕头叉包含 ImageCms
模块。不幸的是,配置文件的构造函数需要文件名或类似文件的对象,因此我们必须通过 io.BytesIO
The Pillow fork of the original PIL library for Python includes a ImageCms
module. Unfortunately the constructor for a profile requires a filename or a file-like object, so we have to do it sideways via io.BytesIO
import io
from PIL import Image
from PIL import ImageCms
image = Image.open('/tmp/DQ-Tool_Print_13x18cm.jpg')
icc = image.info.get('icc_profile')
f = io.BytesIO(icc)
prf = ImageCms.ImageCmsProfile(f)
现在 prf
包含一个颜色配置文件实例。在此处查看文档: https:// pillow.readthedocs.io/en/stable/reference/ImageCms.html#PIL.ImageCms.CmsProfile
Now prf
contains a color profile instance. Have a look at the docs here: https://pillow.readthedocs.io/en/stable/reference/ImageCms.html#PIL.ImageCms.CmsProfile
这篇关于PIL /枕头解码ICC配置文件信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!