I’m trying to dynamically change the color of an image on the screen. To accomplish this, I’m using
visual.ImageStim and changing the colors with
stimulus.color = [r, g, b]. This works great for any color brighter than neutral grey: light colors fade out to grey. However, it does not work for any colors darker than neutral grey. When I try to make the whole image black, for example (
stimulus.color = [-1, -1, -1]), the colors in the image are inverted instead of displaying as black.
The math of the color maps makes sense here: Multiply by a negative number to invert the color. However, the same outcome occurs regardless of whether I use the
rgb or the
Do you have any suggestions for how to dynamically recolor an image to a dark color?
I’m including a minimal working example here.
from psychopy import visual, core import numpy as np CS = 'rgb' # ColorSpace WHITE = [1, 1, 1] LIGHT_GREY = [0.5, 0.5, 0.5] GREY = [0, 0, 0] BLACK = [-1, -1, -1] ## ---- Comment this section in to try a different colorspace # CS = 'rgb255' # ColorSpace # WHITE = [255, 255, 255] # LIGHT_GREY = [200, 200, 200] # GREY = [128, 128, 128] # BLACK = [0, 0, 0] win = visual.Window([800, 800], monitor='testMonitor', color=LIGHT_GREY, colorSpace=CS, units='pix') img = np.array([[-1, 0], [0, 1]]) # Image bitmap stimulus = visual.ImageStim(win=win, image=img, colorSpace=CS, size=(100, 100), units='pix') # Show the normal stimulus stimulus.color = WHITE stimulus.draw() win.flip() core.wait(1.0) # I want to show the stimulus faded to black. # Instead, this inverts the stimulus, showing # black areas as white and vice versa, leaving # neutral grey areas unchanged. stimulus.color = BLACK stimulus.draw() win.flip() core.wait(1.0) # This strategy does work for fading to neutral grey, however. stimulus.color = GREY stimulus.draw() win.flip() core.wait(1.0)