Ask Your Question
0

Is there an error in the color conversion components?

asked 2019-10-04 10:42:39 -0600

tenspd137 gravatar image

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!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-10-04 17:18:11 -0600

crackwitz gravatar image

I see that your Green value is 0. that could be clipping. I would say you lost information right there.

try it with different Lab values that are within the RGB color space.

be aware that opencv isn't all that exact about definitions of color space. gamma curves is one area that is usually completely ignored, also by users.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-10-04 10:42:39 -0600

Seen: 686 times

Last updated: Oct 04 '19