# Converting LUV-->RGB-->LUV results in different values

Hello, I am currently doing a project that involves manipulating images in LUV space (specifically, equating the average magnitude of the UV vector for a set of images), then converting them back to RGB. However, I am having an issue, where if I start with an image in LUV space, then convert it to RGB, then convert it back, the image changes (in Python):

luv1 = copy.copy(obj_colored)
rgb1 = (cv2.cvtColor(np.array(luv1), cv2.COLOR_Luv2RGB)*255).astype('uint8')
luv2 = cv2.cvtColor(np.array(rgb1).astype('float32')/255, cv2.COLOR_RGB2Luv)
rgb2 = (cv2.cvtColor(np.array(luv2), cv2.COLOR_Luv2RGB)*255).astype('uint8')
luv3 = cv2.cvtColor(np.array(rgb1).astype('float32')/255, cv2.COLOR_RGB2Luv)

np.max(luv2-luv1)

np.max(luv3-luv2)


However:

np.max(np.abs(rgb2.astype(float)-rgb1.astype(float)))


So, in short, it seems to be the case that the RGB values don't change: the initial LUV image is cast to some set of RGB values, and when you convert those RGB values back to LUV, you get new values. So, two sets of LUV coordinates seem to map to the same RGB coordinates... and as long as you're creating the LUV values from RGB values, you get consistent results, but if you start with some LUV values and map to RGB, you won't necessarily get the same LUV values if you try to go back the other way.

I have verified that the initial image, obj_colored (which is in LUV space), has values that fall within the acceptable range in all channels (0<L<100, -134<u<220, -140<v<122).

Any idea what might be going on? Are there some LUV values that have no corresponding RGB values, so the conversion algorithm does the best it can?

edit retag close merge delete

Sort by » oldest newest most voted Change this:

luv3 = cv2.cvtColor(np.array(rgb1).astype('float32')/255, cv2.COLOR_RGB2Luv)


to

luv3 = cv2.cvtColor(np.array(rgb2).astype('float32')/255, cv2.COLOR_RGB2Luv)

more

Edited. The LUV results remain different. see the documentation of RGB ↔ CIE Luv*

Note that when converting integer Luv images to RGB the intermediate X, Y and Z values are truncated to [0,2] range to fit white point limitations. It may lead to incorrect representation of colors with odd XYZ values.

more

Official site

GitHub

Wiki

Documentation