Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is there an error in the color conversion components?

When I have an Lab value of [ 0, .74838874, -1.27087235 ] and I use openCV to convert it in python to sRGB, I get the following answer:

lab = np.array([0,.74838847,-1.27087235]).reshape(1,1,3).astype("float32")
srgb = cv2.cvtColor(lab, cv2.COLOR_LAB2RGB)
srgb

array([[[ 0.00192745, 0. , 0.01226838]]], dtype=float32)

when I convert back:

lab2 = cv2.cvtColor(srgb, cv2.COLOR_RGB2LAB)
lab2
[[[ 0.09155273  0.546875   -1.078125  ]]]

Conversions are supposed to be reversible. When I write my own functions and cross-check with other color libraries, the srgb output is [ 0.00192413, -0.00181046, 0.01226782] which indeed converts back to a lab space [ -2.33426657e-06, 7.48420311e-01, -1.27087764e+00 ] - preserving the chroma.

I realize that there may have been a decision to clip rgb values to zero because in real life you can't have a negative value, but when doing conversions through multiple spaces this can cause a problem. Is there a way to request that there be no clipping? Is this expected behavior or is this a bug?

Thanks!