I wonder whether there is an issue when converting between CIE Lab space and the -1:1 RGB space of PsychoPy.
I am setting my stimulus colour from the CIE Lab colour space. In PsychoPy, LAB parameters are converted to RGB (range -1 to 1) which is then used to set the colour of the stimuli. To do this conversion, I am using the cielab2rgb function to take the LAB parameters and return RGB as set out in the example pages here (see also below):
import psychopy.tools.colorspacetools as cst
cielabColor = (53.0, -20.0, 0.0) # greenish color (L*, a*, b*)
rgbColor = cst.cielab2rgb(cielabColor)
This returns the RGB values (-0.82339714, -0.50600726, -0.58329596)
To test this conversion function was accurate before usage, I used this website to get LAB parameters for an RGB value of (0.5, 0.5, 0.5) from 0–1 space. As PsychoPy uses -1 to 1 space for RGB, this pertains to an RGB value of (0, 0, 0).
To get such an RGB value, the required LAB parameters are L = 53.389, a* = 0.00, b* = 0.00.
I was interested in whether if when I enter these LAB parameters into the cielab2rg function it returns (0.00, 0.00, 0.00). However, when I run the code below:
import psychopy.tools.colorspacetools as cst
cielabColor = (53.389, 0.0, 0.0)
rgbColor = cst.cielab2rgb(cielabColor)
print(rgbColor)
I get RGB values of (-0.57184359, -0.57184359, -0.57184359). To rescale these back into the RGB range of 0-1, this pertains to (with some rounding) RGB values of (0.214, 0.214, 0.214), which is quite a way off the “generating” RGB values of (0.5, 0.5, 0.5).
Is there an error in the cielab2rgb function, or is there something awry with my understanding of colour spaces?
Thanks,
Jim