【发布时间】:2019-11-23 18:26:05
【问题描述】:
我参考了以下stackoverflow thread 来计算颜色校正矩阵。
正如上面提到的线程中提到的,我想从 sRGB 颜色空间转换为线性 sRGB 空间,我正在尝试使用pwkit colorspace mapper 代码进行转换。
但是,我不确定生成的线性 sRGB 值,因为该函数需要 [0-1] 范围内的 sRGB,将 sRGB 值除以 255.0,正确的方法是什么?如何验证函数返回的线性 sRGB 值是否正确?
import os
import numpy as np
import cv2
import matplotlib.pyplot as plt
def srgb_to_linsrgb (srgb):
"""Convert sRGB values to physically linear ones. The transformation is
uniform in RGB, so *srgb* can be of any shape.
*srgb* values should range between 0 and 1, inclusively.
"""
gamma = ((srgb + 0.055) / 1.055)**2.4
scale = srgb / 12.92
return np.where (srgb > 0.04045, gamma, scale)
if __name__ == "__main__":
colorChecker = cv2.imread('C:/Users/Ai/Documents/Urine Sample Analysis/Assets/colorchecker_1.jpg')
cc = cv2.cvtColor(colorChecker,cv2.COLOR_BGR2RGB)
plt.imshow(cc)
#Convert srgb to linear rgb
cc = cc / 255.0
cc1 = srgb_to_linsrgb(cc)
print("Conversion from sRGB to linear RGB:\n")
print(cc1[1,1,:])
转换结果为:[0.30946892 0.23455058 0.19806932]
输入的 sRGB 应该在 0-1 之间,如何将 sRGB 通道的值从 [0-255] 缩放到 [0-1],简单除以 255.0 会产生正确的线性 sRGB 值吗?如何验证转换是否产生了正确的线性 sRGB 值?
【问题讨论】:
标签: python opencv image-processing colors