psychopy.org | Reference | Downloads | Github

Applying Gaussian filter to shape stimulus

Dear all,

I am using PsychoPy 2020.1.2. on a Macbook (Mojave) to code a visual experiment. As part of the trial, I would like to present a white oriented response bar, that I would like to smooth a bit around the edges with a type of Gaussian contrast filter. So far, I have not been able to implement this properly and am running out of ideas. I have essentially tried the following:

  1. Use the visual.rect object to create the bar, hoping that I would be able to get access to an actual “texture object” (as is, for instance, the case with the visual.GratingStim object), that I could then simply apply a Gaussian filter to. Perhaps I am missing something, but it appears to me that this is not actually the case and that the rectangle is simply defined by its vertices? Is there any way to get access to such a “texture array?”

  2. Create a texture (in the shape of a bar) and pass that to the visual.GratingStim object in conjunction with a Gaussian mask.

respBar = np.ones((128, 128))*(-1) #generate white square the same size as the stimulus
respBar[:, int(np.shape(respBar)[0]/2 - 5) : int(np.shape(respBar)[0]/2 +5)] = 1
respBar = -respBar

respBarStim = visual.GratingStim(win, tex=respBar, mask='gauss', units='deg', ori=36, color='dimgray', size=1.5)

But then I am running into a problem getting the colours of the stimulus right:

I would like the response bar to be white on a dim gray background. But it seems to me that as soon as I set the color of the visual.GratingStim to be dim gray (which is the background color of my screen), I am unable to generate a white bar. The bar in this scenario always takes on a lighter gray than the background. Obviously, I am missing something, but I can’t figure out exactly what it is. How do I have to define the colours correctly to get a white bar on a dim gray background?

Many, many thanks!

2 Likes