python OCIO 颜色空间转换 - 颜色问题

问题描述 投票:0回答:1

我有一个使用 ACEScc 色彩空间的测试 16 位 tiff 文件:

我想使用 OCIO 对其进行处理,例如线性 sRGB。 OCIO 提供了如何执行此操作的示例: https://opencolorio.readthedocs.io/en/latest/guides/developing/developing.html 使用起来似乎很简单:

import cv2
import numpy as np
import PyOpenColorIO as OCIO

path = "ACEScc.tif"

input_cs = "ACES - ACEScc"
output_cs = "Utility - Linear - sRGB"

img = cv2.imread(path)

#I use the default config downloaded from OCIO website
config = OCIO.Config.CreateFromFile("config.ocio")
in_colour = config.getColorSpace(input_cs)
out_colour = config.getColorSpace(output_cs)
processor = config.getProcessor(in_colour, out_colour)
cpu = processor.getDefaultCPUProcessor()

#this seems to be missing in the docs. the processor seems to expect floating point values 
#scaled to 0-1 range. Here I might be doing it wrong and this might be causing the colour issues.

img2 = img.astype(np.float32) / 255.0

cpu.applyRGB(img2)

#take it back to 8bit to have something to look at:
img3 = (img2*255.0).astype(np.uint8)

cv2.imwrite(r"ocio_test.tif", img3)

生成的图像已正确线性化。超出 8 位范围的值将被剪裁(这是预料之中的,我没有以任何方式处理它)。然而,没有剪裁的颜色是不正确的。我错过了什么?

这是 macbeth 图表的特写,显示了颜色问题(左边是正确的,右边是我从上面的 python 中得到的)

有些颜色还可以,但黄色和橙色变成了粉色。也没想到绿植竟然超出了范围。 我使用从此处下载的 ocio v1 和 v2 配置进行了测试: https://opencolorio.readthedocs.io/en/latest/quick_start/downloads.html

我不确定这里的问题是什么,希望有任何建议。

python image-processing colors openimageio
1个回答
0
投票

这里的问题在于用于测试的 TIFF 文件。事实证明,openCV 将文件加载为 BGR(我希望它能够在内部进行清理并始终将数据存储为 RGB)。显然,OCIO 中的矩阵没有预期这个顺序,并且搞乱了颜色。 这里的一个简单修复方法是在传递给 OCIO 之前将通道从 BGR 重新排列为 RGB:

img = img[:,:,::-1]

© www.soinside.com 2019 - 2024. All rights reserved.