@djmannion Great idea, thank you so much! I can’t modify the code to make it fullscreen though. I tried this :
import numpy as np
from psychopy import visual, event, core, gui
img_size = 128
#win_size = img_size * 2#256
#img_frac = img_size / win_size
# probability of a pixel reversing in polarity
p_flip = 0.1
# whether to flip each pixel, as a vector; start as unflipped
pix_mod = np.ones(540*960)
# number of pixels to flip
n_to_flip = np.round((540*960) * p_flip).astype(int)
# set the required proportion to flip
pix_mod[:n_to_flip] = -1
# randomise their positions
np.random.shuffle(pix_mod)
# convert into an image
pix_mod = np.reshape(a=pix_mod, newshape=(540,960))#(128,128) array
pix_mod = pix_mod[..., np.newaxis]#(432,768,1) array (height, width, number of color channels (grayscale here))
win = visual.Window(monitor='mathieu', color=[0,0,0], colorSpace='rgb255', units='norm', fullscr=True)
expName="lexical decision"
expInfo={'participant':''}
dlg=gui.DlgFromDict(dictionary=expInfo,title=expName, order=['participant'])
if dlg.OK==False: core.quit() #user pressed cancel
text = visual.TextStim(
win=win, text="F", height=0.15, antialias=False, units="norm", fullscr=True)
#text.draw()
#win.flip()
#event.waitKeys()
#core.quit()
#
### region of the window to capture
capture_rect = [-0.5, 0.5, 0.5, -0.5] #[left, top, right, bottom]
##
### get the image of the letter
buff = visual.BufferImageStim(win=win, stim=[text], interpolate=False, rect=capture_rect)#screen shot of the stimulus in the back buffer (hidden), norm units (mandatory)
#
#
## convert from [0, 255] to [-1, +1]
buff_img = np.array(buff.image).astype("float") / 255.0 * 2.0 - 1.0
#
## do the polarity flipping
img = np.flipud(buff_img) * pix_mod
#
## generate a stimulus to show the noisy image
img_tex = visual.GratingStim(
win=win, tex=img, mask=None, size=(540*960), units="pix")
#
img_tex.draw()
win.flip()
#
#event.waitKeys()
event.waitKeys()
core.quit()
Which does not even return something fullscreen! There might something with the BufferImageStim function that I don’t understand. Any idea?
There is another complication when switching to fullscreen mode. On windows 10 (15’ laptop), 1920*1080 resolution, psychopy uses an incorrect resolution (WARNING User requested fullscreen with size [800 600], but screen is actually [1536, 864]). I think Psychopy uses the default 125% scaling from windows. However, adding a gui at the beginning of the code e.g.
expName="lexical decision"
expInfo={'participant':''}
dlg=gui.DlgFromDict(dictionary=expInfo,title=expName, order=['participant'])
if dlg.OK==False: core.quit()
solves the issue (Psychopy now identify the 1920*1080 resolution) so I am a little lost here. Maybe @jon has some insight on this? (note: I am using Psychopy v3.2.4)