Dkl2rgb not working to convert colours from DKL to RGB color space

Hi there,

OS windows 7
PsychoPy version 1.85.6
Standard Standalone? (y/n) Yes
Although, also having the same problems on windows 10, PsychoPy v2020.2.10 with the same script below and error messages.

What are you trying to achieve?:
I’m trying to create colours in DKL space and convert into RGB space using the dkl2rgb function. Below is a script where I am just trying to create the colours, however I only keep getting errors:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from __future__ import division
from psychopy.tools.colorspacetools import dkl2rgb
from psychopy import visual, event, core, misc
import numpy as np  

win = visual.Window((800, 800), allowGUI=False, units = 'pix', color = "darkgrey")

midcol = [0, 191, 1] 

midcolour = dkl2rgb(midcol, conversionMatrix = 'none')

circle1 = visual.Circle(win, fillColor = midcolour, radius = 40, pos = [0, 0], fillColorSpace='dkl')

while not event.getKeys():
    circle1.draw()
    win.flip()  

win.close()
core.quit()

This is the error I get:


Traceback (most recent call last):
  File "I:\Giessen postdoc\testing colours dkl.py", line 59, in <module>
    midcolour = dkl2rgb(midcol, conversionMatrix = 'none')
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\tools\colorspacetools.py", line 40, in dkl2rgb
    if len(dkl.shape) == 3:
AttributeError: 'tuple' object has no attribute 'shape'

I then tried an array with this:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from __future__ import division
from psychopy.tools.colorspacetools import dkl2rgb
from psychopy import visual, event, core, misc
import numpy as np  

win = visual.Window((800, 800), allowGUI=False, units = 'pix', color = "darkgrey")

midcol = np.asarray((0, 191, 1))

midcolour = dkl2rgb(midcol, conversionMatrix = 'none')

circle1 = visual.Circle(win, fillColor = midcolour, radius = 40, pos = [0, 0], fillColorSpace='dkl')

while not event.getKeys():
    circle1.draw()
    win.flip()  

win.close()
core.quit()

Then got this error message:

Traceback (most recent call last):
  File "I:\Giessen postdoc\testing colours dkl.py", line 59, in <module>
    midcolour = dkl2rgb(midcol, conversionMatrix = 'none')
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\tools\colorspacetools.py", line 62, in dkl2rgb
    rgb = numpy.dot(conversionMatrix, dkl_cartesian)
TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe'

Any advice would be much appreciated.

I think I know the problem - in 2021.1.0 we’re using a new class to handle colours behind the scenes, this is the first version in which it’s linked to any stimuli but the class has been there (and used in a few colour conversion functions) since 2020.2.0. I think the problem here is the discrepancy between the output of the class and the output of the old functions, which caused us some problems when integrating it for 2021.1.0. Meaning that in the new release these issues are fixed, so if you update to 2021.1.0 this should no longer be a problem :slight_smile:

Hi,

Thanks for your response. I updated to 2021.1.0, although I’m still getting the same errors as above when I try to use dkl2rgb.

Try passing your color as a numpy array. For instance, midcol = np.asarray(midcol) will convert it. I think that function needs to be eventually modified on our end to perform that step on all inputs.

Edit: just noticed you tried that :confused:

Can’t replicate this issue, since the function works correctly on my end. I think you need to call the function with conversionMatrix=None instead of conversionMatrix='none' which is invalid syntax.

Still will give you an error if midcol is not a numpy array. I fixed both these issues on our end, should make it out in the next bugfix release.

1 Like

Thanks! It works now with the following:

midcol = np.asarray([0, 191, 1])
midcolour = dkl2rgb(midcol, conversionMatrix = None)