Converting from RGB to LAB yields strange results, but vice versa works fine

asked 2018-12-14 06:12:20 -0600

LeBorzi gravatar image

updated 2018-12-14 06:20:02 -0600

I have a RGB image that I want to convert to LAB. When trying to convert an image from LAB colour space to RGB it works fine, but when I want to convert RGB->LAB, the luminance value for all pixels is 100, while the ab values for all pixels are 0. Anyone know why? This is the code I am using:

lab_img = cv2.cvtColor(rgb_img.astype(np.float32), cv2.COLOR_RGB2LAB)

I actually had a copy of a LAB image and tried to reverse the process, first converting the said image to RGB (which worked fine) and then convert the result back to LAB (didn't work).

edit retag flag offensive close merge delete

Comments

I didn't test your code, but I don't understand why are you transforming your image to float...?

In float format, 0 is considered black, 1 is white. Maybe that's why the luminosity channel is saturated.

kbarni gravatar imagekbarni ( 2018-12-15 17:09:19 -0600 )edit