python - PIL/Pillow 解码 icc 配置文件信息

标签 python encoding python-imaging-library color-profile

我坚持解码/解析使用 PIL 提取的 ICC 配置文件信息。

在包含“Adobe RGB (1998)”配置文件的测试图像下方。

# 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 信息的方法。

上面的例子会返回:

'\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)”

有什么想法吗?期待您的意见 :)!

Test image with embeded Adobe RGB (1998) profile

最佳答案

我写这篇文章也是为了那些来这里搜索有关如何在 Python 中处理 ICC 颜色配置文件信息的人。

Pillow fork Python 的原始 PIL 库包括一个 ImageCms 模块。不幸的是,配置文件的构造函数需要文件名或类似文件的对象,因此我们必须通过 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

关于python - PIL/Pillow 解码 icc 配置文件信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31865743/

相关文章:

python - 无法获取 Gtk.ListBox() 对象以在运行时在 Python 中添加新的 Gtk.ListBoxRow() 对象

windows - 使用 Media Foundation 进行硬件 H264 编码 ID3D11Texture2D

PHP curl 返回奇怪的字符

python - 导入在 Python shell 中工作,但在从文件运行时不起作用

python - 在 Python 中静音/取消静音扬声器

python - 模块未找到错误 : No module named 'mnist'

python - Tkinter:更改窗口顶部栏的颜色

node.js - 默认情况下 NodeJS 加密和二进制编码

Python PIL Crop 不裁剪图像

python-3.x - 如何获取 ImageDraw 对象数组?