问题描述
我正在尝试将RGB转换为感知上均匀的色彩空间CIELAB。维基百科声明:
I am trying to convert an RGB to the perceptually uniform color space, CIELAB. Wikipedia states:
我知道转换为sRGB后有一些简单的转换,但我还没有找到任何转换材料从RGB到sRGB。那么,有什么方法可以进行这样的转换?
I know there are some straightforward transformations once converting to sRGB, but I have not found any material to go from RGB to sRGB. So, what methods exist to do such a conversion?
推荐答案
不,你不应该从(线性)RGB转到sRGB。事实上,它是相反的。以下是步骤:
No, you should not go from (linear) RGB to sRGB. In fact, it is the other way round. Following are the steps:
-
将sRGB转换为线性RGB。 sRGB图像是伽马编码,这意味着摄像机将伽马函数 pow(x,1 / 2.2)应用于光信号。此sRGB位于非线性的伽马空间中。
Convert sRGB into linear RGB. sRGB image is a gamma encoded which means a camera applies gamma function pow(x, 1/2.2) onto the light signal. This sRGB is in gamma-space which is non-linear.
现在,将线性RGB转换为LAB涉及两个步骤:首先将线性RGB转换为XYZ颜色空间(这是一个基本的颜色空间)。该转换是线性运算,即矩阵乘法。这就是为什么你需要线性RGB值而不是sRGB的原因。它需要处于线性空间。最后,通过非线性操作将XYZ值转换为LAB值,该操作包含一些标准公式(您不必担心)。
Now, converting linear RGB to LAB involves two steps: first is converting linear RGB to XYZ color space (this is a basic color-space). This conversion is a linear operation, i.e., matrix multiplication. This is the reason why you would need linear RGB values not sRGB. It needs to be in linear space. Finally, XYZ values are converted into LAB values through a non-linear operation which contains some standard formulas (which you don't need to be worried about).
有趣的链接:
(i)了解sRGB和线性RGB空间:;
(ii) MATLAB tutorial: https://de.mathworks.com/help/vision/ref/colorspaceconversion.html
(iii)Python包:
(iii) Python package: http://pydoc.net/Python/pwkit/0.2.1/pwkit.colormaps/
(iv)C代码:
(v)OpenCV不执行此sRGB到线性RGB转换,但它在color.cpp代码中执行转换(OpenCV_DIR\modules\imgproc\src\color.cpp)。检查出名为 initLabTabs()的方法,有一个gamma编码和解码。 OpenCV颜色转换API:
(v) OpenCV does not do this sRGB to linear RGB conversion but it does the conversion inside color.cpp code (OpenCV_DIR\modules\imgproc\src\color.cpp). Check out method called initLabTabs(), there is a gamma encoding and decoding. OpenCV color conversion API: http://docs.opencv.org/3.1.0/de/d25/imgproc_color_conversions.html
这篇关于将RGB转换为sRGB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!