I would like to precisely control the signal-to-noise contrast ratio for a Gabor grating in noise. According to this link here OpenGL and Rendering — PsychoPy v2021.2, for blendMode = ‘avg’ in visual.Window:
Mathematically, each pixel colour is constructed from opacity*stimRGB + (1-opacity)*backgroundRGB.
My understanding is that, if I draw the noise patch first, it’ll be in the background. If I then draw the Gabor patch on top of it, every overlapping pixels should be computed based on the opacity of the Gabor. If I set Gabor’s opacity to 1.0, then the noise pixels should be given a zero weight, and they should not be visible at all.
I tried doing this using the code below:
from psychopy import visual, core, event from numpy.random import random # open window win = visual.Window([1024,768],units='pix',monitor='testMonitor',blendMode='avg') X = 128; # width of gabor patch in pixels sf = .05; # cycles per pixel noiseTexture = random([X,X])*2.-1. # a X-by-X array of random numbers in [-1,1] # signal grating patch s = visual.GratingStim( win = win, mask='gauss', sf = sf, size = X, contrast = 1.0, opacity = 1.0, ) # noise patch n = visual.GratingStim( win = win, mask='gauss', tex = noiseTexture, size = X, contrast = 1.0, opacity = 1.0, ) while not event.getKeys(): n.draw() # draw noise in the background s.draw() # draw gabor on top of noise win.flip() event.clearEvents('mouse') # for pygame only win.close() core.quit()
but I still see the noise pixels:
I thought someone might have asked this but I couldn’t find a relevant post… maybe I’m missing something here. Ultimately, I just want to have a way to precisely control the signal-to-noise contrast ratio between a Gabor patch (as signal) relative to the noise pixels. If there’s a better way to do it, I’d love to know!
I’m running PsychoPy 1.8x on Spyder 3 (Python 2.7) in Anaconda 2, in lubuntu 18.04 (I don’t remember the exact version of PsychoPy installed…).