| Reference | Downloads | Github

Grabing image content from window

Dear all,

I want to save the raw pixel representation of my presented stimuli. To make the stimuli, I use GratingStim with the appropriate parameters. After drawing the content to the screen and flipping the window, I would like to extract the matrix representation containing the rgb values for all individual pixels. In psuedo-code something like this:

# Create the variables
window = visual.window(...)
grating = visual.GratingStim(...)

# And then something like..
image = grating.getPixelValues()
# Or maybe?
image = window.getPixelValues()

This is similar to PsychToolbox’ Screen(window, “GetImage”). How can one achieve this, or is it possible at all in Psychopy?

Many thanks!

Hi Jordy,
It’s an interesting question so I experimented a little bit myself. It seems, you can easily get your displayed frame as PIL.image and save it with


with win being an instance of psychopy.visual.Window.

I hope this helps.


Hi Schubisu,

Amazing! Thanks a million! The solution I was searching for was just the following:

# Grabe image content as matrix, i.e. its pixel values (rgb)
image = np.array(window._getFrame())

Issue solved!