Ask Your Question
0

May I ask why I get the wrong answer about rgb2luv

asked 2015-11-17 06:55:26 -0600

updated 2015-11-17 07:28:45 -0600

thdrksdfthmn gravatar image

I use python. Today I try to convert an image(rgb) to luv.

The Doc

However , I am confused with the result.So I have a trial.

import cv2
import numpy as np
im=np.array([[[0.78039217, 0.73333335, 0.73333335]]],dtype=float32)
im_xyz=cv2.cvtColor(im,cv2.COLOR_RGB2XYZ) #the result is array([[[ 0.71641064, 0.74334133, 0.79932952]]], dtype=float32)
im_luv=cv2.cvtColor(im,cv2.COLOR_RGB2LUV)#array([[[ 76.84296417, 6.9851861 , 1.50677502]]], dtype=float32)

However,I use the matlab to rgb2luv,the result is 89.0798 , 3.5388 , 0.7616. So I try the xyz to luv, the value of L is also is 89.08016438386028. Why the result of the function cvtColor(im,cv2.COLOR_RGB2LUV) is not 89? 3Qs a lot.

edit retag flag offensive close merge delete

Comments

1

As far as I know, Matlab does not have an official rgb2luv function (if I'm wrong, please point me to the corresponding docs). So probably the function you're using is implemented differently. About OpenCV one, here more info

LorenaGdL gravatar imageLorenaGdL ( 2015-11-17 09:09:43 -0600 )edit
1

Be careful, OpenCV loads an image by default as BGR

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-11-17 10:18:01 -0600 )edit

Yes,I know the BGR which also confused me a lot.

h12345jack gravatar imageh12345jack ( 2015-11-18 04:06:36 -0600 )edit

actually Matlab doesn't the official one. My rgb2luv comes from here, And I feel confused about the luv doesn't -16,which is 116y^(1/3) but 116y^(1/3) -16, Could you tell my the reason?3Qs a lot .

h12345jack gravatar imageh12345jack ( 2015-11-18 04:12:54 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2015-11-17 13:32:17 -0600

pklab gravatar image

I suppose that in OpenCV, Luv* and Lab* color conversion uses the nonlinear R’G’B’ coding that is quite perceptually uniform:

R'G'B' = LabCbrtTab(RGB)

where LabCbrtTab is a lookup table of nonlinear rising slope that consider the luminance of the white reference Yn.

X'Y'Z' = ConvertToXYZ(R'G'B')
L = 116 * Y' - 16

I suppose that the implementation in matlab uses linear RGB coding assuming the luminance of the white reference Yn=1

XYZ = ConvertToXYZ(RGB)
L = 116 * (Y/Yn)^(1/3) - 16

May be you had used this formula to calculate the xyz to luv.

In any case there is a discrepancy between the code and the doc

the doc: L = 116 * Y^(1/3)
the code L = 116 * Y'- 16

I know this don't help so much, if you want you can investigate the code here: <OCV_ROOT>/modules/imgproc/src/color.cpp, RGB2Luv_f, operator()

edit flag offensive delete link more

Comments

So I need to do xyz2luv with numpy myself?

h12345jack gravatar imageh12345jack ( 2015-11-18 04:53:00 -0600 )edit

Is matlab rgb2luv official ? Luv color system is subjective to human perception and depends on gamma and withepoint... some standards was proposed but you could have different values from different implementations... what implementation you trust ? If you are using some .m around the net take care of it, may be is too simple because L* = 116(Y/Yn)^(1/3)-16 and use Yn=1 is a semplification. ImageJ rgb2luv gives same value for L* as OpenCV for 8bit images. Thest it with floating point images and let us know

pklab gravatar imagepklab ( 2015-11-18 06:19:00 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-11-17 06:49:31 -0600

Seen: 644 times

Last updated: Nov 17 '15