我想将一组像素值从一个配置文件色彩空间转换为另一个,而不将这些值驻留在图像文件中,例如(例如)RGB/RGBA/CMYK/等数据结构的列表。
我有 Python 和 PIL 可供使用,但我对相关环境中的解决方案感兴趣如果这就是所需要的。
最新的 PIL 对 LittleCMS 提供了非常好的支持——但除了 PIL 图像之外没有办法提供任何东西(或旧版 pyCMS 对象)以供其执行操作。
据我所知,LittleCMS 中包含的命令行工具 icctrans
可以执行此类操作,但我似乎找不到任何关于它的非骨架文档,文档参考将其作为演示工具。
I'd like to convert a set of pixel values from one profiled colorspace to another, without these values residing in an image file, such as (say) a list of RGB/RGBA/CMYK/etc data structures.
I have Python and PIL at my disposal, but I'm interested in solutions in related environments if that's what it takes.
The latest PIL has very nice support for LittleCMS -- but no way to hand it anything other than a PIL image (or a legacy pyCMS object) for it to act upon.
As far as I can ascertain, the command-line tool icctrans
that's included with LittleCMS does something of this sort, but I can't seem to find any non-skeletal documentation on it, and the documentation refers to it as a demonstration tool.
发布评论
评论(2)
为了在 Python 中使用当前 2.3 版本的 Little CMS,我翻译了
lcms2.hh2py.py
脚本将 code> 转换为lcms2consts.py
。该脚本不会转换结构声明,但常量足以使用ctypes
和lcms2
作为动态库进行基本颜色转换。此示例使用内置配置文件将单色从双精度 Lab 转换为 8 位 sRGB。使用
cmsOpenProfileFromFile(filename, 'r')
代替文件。In order to use the current 2.3 version of Little CMS with Python, I translated
lcms2.h
tolcms2consts.py
with theh2py.py
script that comes in the Python distribution. The script does not translate struct declarations, but the constants are enough to do basic color transformations withctypes
andlcms2
as a dynamic library.This example transforms a single colour from double precision Lab to 8-bit sRGB using built-in profiles. Use
cmsOpenProfileFromFile(filename, 'r')
instead for files.有两种方法。
破解方法:要重新配置 N 个颜色结构(和/或在颜色空间之间转换它们),您可以使用
PIL.Image.new()< 创建一个 1x(N+2) 图像/code>,使用
yourimage.load()
获取像素设置对象接口事物,并将值 (0,0) 到 (0, N) 设置为您获得的值。将 (0, N+1) 设置为白色,将 (0, N+2) 设置为黑色,然后使用您最喜欢的 ICC 文件和PIL.ImageCms.ImageCmsTransform() 转换(或校对转换)该图像。 >。 Blammo:那个 PIL 对象现在是你的 LUT。使用
image.load()
读取这些值就可以了。真正的书呆子方式:您需要使用Python -colormath——这对于色彩空间转换非常有用,但不适合分析。 Colormath 无法读取 ICC 配置文件,因此 a) 您可以以可靠的方式解析其疯狂的二进制格式,或者 b) 只是做数学计算,字面意思。 Bruce Lindbloom 拥有 Excel 格式的所有可用数据,例如 所有重新配置 LUT 所需的矩阵。他太棒了。我仍在尝试“只是”将这些数据输入到色彩数学中,所以是的,这让我不那么出色,因为我仍在尝试将这种“书呆子方式”转化为类似于生产质量的东西。
就这样吧。这就是我迄今为止为回答独立式、突击队式 ICC LUT 转换问题所做的工作。你们,srsly。
There are two ways.
The hack way: To reprofile N color structures (and/or transform them between colorspaces) you create a 1x(N+2) image with
PIL.Image.new()
, useyourimage.load()
to get a pixel-setting object interface thing, and set values (0,0) through (0, N) to whatever you got. Set (0, N+1) to white and (0, N+2) to black, and transform (or proof-transform) that image using your favorite ICC files andPIL.ImageCms.ImageCmsTransform()
. Blammo: that PIL object is now your LUT. Read the values off with theimage.load()
thingy and you're good.The true-nerd way: You need to use Python-colormath -- which is great for colorspace transforms but not profiling. Colormath can't read ICC profiles, so either a) you get to parse their crazy binary format in a reliable way, or b) just do the math, literally. This guy Bruce Lindbloom has all the data available in excel format for, like, all of the matricies you need to reprofile your LUTs. He is totally awesome. I am still trying to 'just' feed this data into colormath, so yeah, that makes me less awesome as I am still trying to get this 'nerd way' into something resembling production-quality.
There you go. That is what I did so far to answer the question of freestanding, commando-style ICC LUT transforms. U guys, srsly.