Ask Your Question
0

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

asked 2018-12-13 15:59:50 -0600

updated 2018-12-16 06:42:43 -0600

berak gravatar image

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)
Answer: 21.93

np.max(luv3-luv2)
Answer: 0.78480256

However:

np.max(np.abs(rgb2.astype(float)-rgb1.astype(float)))
Answer: 1 **barely any change**

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 flag offensive close merge delete

Comments

test comment

berak gravatar imageberak ( 2018-12-16 06:41:31 -0600 )edit

3 answers

Sort by » oldest newest most voted
1

answered 2018-12-13 21:03:30 -0600

supra56 gravatar image

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)
edit flag offensive delete link more

Comments

Edited. The LUV results remain different.

johnmark_taylor gravatar imagejohnmark_taylor ( 2018-12-14 15:45:13 -0600 )edit
0

answered 2018-12-14 16:17:04 -0600

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.
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-12-13 15:56:07 -0600

Seen: 2,316 times

Last updated: Dec 16 '18