io
io copied to clipboard
RGB to LAB conversion color space range
Hello,
I'm trying to use the rgb_to_lab function (doc) but I have found that the range of values different from the standard. The range of values for L is 0-100 while for A is -127 to 128 and for B its -128 to 127. However, when I use the rgb_to_lab the values are completely out of range (in the 1000s). I have cross checked with scikit image and I think I might have figured out why this happens. The gist is that scikit-image's implementation gives the wrong values if I provide the input RGB image which is of type float (float16 or float32). However, the input is supposed to be of uint8 type and only with this input type you get the correct result. But this is not possible with the TF IO's rgb_to_lab function as it expects the input to be of the type tf.float16 or tf.float32 or tf.float64. So I think TF IO's rgb_to_lab function will return the correct LAB image if the input was of type tf.uint8 but I'm not 100% sure as this hasn't been verified.
Upon taking a deeper look, I have noticed two things:
rgb_to_labfunction seems to work fine if the input rgb image is normalised to have pixel values between 0 and 1. But this is not mentioned anywhere in the documentation and by the name of the function, one would expect this to work on pure RGB images given as input too.- It's using the LAB implementation where the values for A and B are between -110 and 110.
I would like someone to verify my findings.
@abhishekthanki Our implementation matches skimage.color.rgb2lab (as was shown in the test):
https://github.com/tensorflow/io/blob/master/tests/test_color.py#L127
If this is different from the standard we can update the implementation as needed. We may need a verifiable standard as a reference though.