# Grabing image content from window

**URL:** <https://discourse.psychopy.org/t/grabing-image-content-from-window/3463>\
**Category:** Coding\
**Tags:** screen\
**Created:** [November 16, 2017, 10:52pm UTC](https://discourse.psychopy.org/t/grabing-image-content-from-window/3463 "2017-11-16T22:52:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thijor](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@thijor](https://discourse.psychopy.org/u/thijor)\
**Post date:** [November 16, 2017, 10:52pm UTC](https://discourse.psychopy.org/t/grabing-image-content-from-window/3463/1 "2017-11-16T22:52:37Z")

</div>

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:

```auto
# Create the variables
window = visual.window(...)
grating = visual.GratingStim(...)
grating.draw()
window.flip()

# 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!  
Jordy

---

<div class="post-metadata">

**Author:** ![schubisu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/schubisu/32/1686_2.png) [@schubisu](https://discourse.psychopy.org/u/schubisu)\
**Post date:** [November 17, 2017, 10:20am UTC](https://discourse.psychopy.org/t/grabing-image-content-from-window/3463/2 "2017-11-17T10:20:53Z")

</div>

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

`win._getFrame().save('myimage.png')`

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

I hope this helps.  
Best,  
Robin

---

<div class="post-metadata">

**Author:** ![thijor](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@thijor](https://discourse.psychopy.org/u/thijor)\
**Post date:** [November 17, 2017, 10:51am UTC](https://discourse.psychopy.org/t/grabing-image-content-from-window/3463/3 "2017-11-17T10:51:59Z")

</div>

Hi Schubisu,

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

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

```

Issue solved!
