| Reference | Downloads | Github

Question regarding white noise generation with filters.makeMask and visual.Stim

Hi there,

This is based off the following thread: Creating bandpass Gaussian white noise - #2 by jon

I am looking to generate white noise with the noise blobs that scales with the size of the grating stripes as shown in the example:

The problem I have here, is that I need it be absolute noise, and not with the systematic grating partially visible especially in the case of the biggest gabor. visual.GratingStim allows the use of noise texture overlay. On top of it, there is a Gaussian masking available. These are two things I need which unfortunately, does not seem to work with visual.Circle. Is there a way to rid the gratings in GratingStim? Or is there an alternative visual.stim that I can use to replace GratingStim here?

My codes are:

from psychopy import core, visual, event, sound, logging, filters
import numpy as np

## Noise defined by resolution (array) and radius of blob
def makeFilteredNoise(res, radius, shape='gauss'):
    noise = np.random.random([res, res])
    kernel = filters.makeMask(res, shape=shape, radius=radius)
    filteredNoise = filters.conv2d(kernel, noise)
    filteredNoise = (filteredNoise-filteredNoise.min())/(filteredNoise.max()-filteredNoise.min())*2-1
    return filteredNoise

size1 = 1.19; size2 = 2.49; size3 = 5.09 #size of the 3 gabors in degrees
spafreq = 4. #number of grating cycles

filteredNoise1 = makeFilteredNoise(64, (size1/spafreq)/2) #size divided by spafreq (blob size)
filteredNoise2 = makeFilteredNoise(64, (size2/spafreq)/2) #size divided by spafreq
filteredNoise3 = makeFilteredNoise(512, (size3/spafreq)/2) #size divided by spafreq

# create a window to draw in
win = visual.Window([600.0, 600.0], allowGUI=False, waitBlanking = False, fullscr=False, 
                    color=[-0.2,-0.2,-0.2],monitor='default', units='deg')

gabor1 = visual.GratingStim(win, tex="sin", mask="gauss", texRes=128, 
           size=[size1,size1], units="deg", ori = 45, pos=[-3,2])

gabor2 = visual.GratingStim(win, tex="sin", mask="gauss", texRes=128, 
           size=[size2,size2], units="deg", ori = 45, pos=[-0.5,2])

gabor3 = visual.GratingStim(win, tex="sin", mask="gauss", texRes=128, 
           size=[size3,size3], units="deg", ori = 45, pos=[3,2])

spafreq1 = spafreq/size1 #1.19
spafreq2 = spafreq/size2 #2.165
spafreq3 = spafreq/size3 #3.79

gabor1.sf = spafreq1; gabor2.sf = spafreq2; gabor3.sf = spafreq3

noise1 = visual.GratingStim(win, tex=filteredNoise1,
        units='deg',mask='gauss', pos=[-3,-2],
        interpolate=False, ori = 0, autoLog=False)
noise2 = visual.GratingStim(win, tex=filteredNoise2,
        units='deg',mask='gauss', pos=[-0.5,-2],
        interpolate=False, ori = 0, autoLog=False)
noise3 = visual.GratingStim(win, tex=filteredNoise3,
        units='deg',mask='gauss', pos=[3,-2],
        interpolate=False, ori = 0, autoLog=False)

display = True

while display == True:
    for key in event.getKeys(keyList=['escape']):
        #quit at any point
        if key in ['escape']: