Greetings Réka,
I may have a solution that you could use.
For starters, you can use an ImageStim in builder, but in a slightly different way than normal.
Rather than passing the ImageStim a file name in Image, you can pass it an array that has the RGB (or Grayscale) values you want.
# will use it for noise generation
import numpy as np
# will use it to load images
import scipy.ndimage as spi
# load the image and convert it to a 0.0 to 1.0 range (the range PsychoPy uses with RGB images)
img = spi.imread("stimuli/8.png", mode = "RGBA")/255.0
If you load your images as arrays, you can freely add noise to them.
noise_level = 1.
# generates noise from negative noise_level to positive noise_level (-1 to 1, in this case)
# because the shape of the np noise array is (width, height, 1), it can broadcast onto any number of dimensions, meaning you could use grayscale or RGB and still have the 'white static' look.
presented = img + 2*np.random.random((img.shape[0],img.shape[1], 1))*noise_level-noise_level
However, the presented stimulus must not exceed the bounds of 0 and 1 or you will get a glitchy looking picture. So, use numpy’s where function to fix the out of bounds values.
# set values that are higher than 1 to 1
presented[np.where(presented >1)] = 1.
# set values that are lower than 0 to 0
presented[np.where(presented <0)] = 0.
You can make the ImageStim use $presented in the “Image” field that you should set to change during an ISI that runs the code each “begin routine”. Also, loading an image with scipy means that you need to make the Y value for the image Size field a negative value so it flips up/down.
Ideally, you would use a Builder view loop with a spreadsheet that had a list of filenames in a column called “filename” (no quotes). That way, a different filename would be loaded for each trial:
# changing the load code to allow trial by trial filenames
# "stimuli" is just a folder I made to test this.
img = spi.imread("stimuli/{0}".format(filename), mode = "RGBA")/255.0
That should cover it.
It’s my first post here, so I’m not sure if the Markdown will show properly.
Jason