# Builder: NoiseStim to ImageStim

**URL:** <https://discourse.psychopy.org/t/builder-noisestim-to-imagestim/16146>\
**Category:** Builder\
**Created:** [September 1, 2020, 10:01pm UTC](https://discourse.psychopy.org/t/builder-noisestim-to-imagestim/16146 "2020-09-01T22:01:53Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [September 2, 2020, 10:07am UTC](https://discourse.psychopy.org/t/builder-noisestim-to-imagestim/16146/2 "2020-09-02T10:07:51Z")

</div>

Hi There,

You can feed set an alpha mask to crop the image and then save the window to save the image.

Try:

```auto

#import modules
from psychopy import core, visual 
import numpy as np

# Create a window to draw in
win = visual.Window(size=(600, 600), color='black', monitor='testMonitor')

#function to crop np array 
def crop_center(img,cropx,cropy):
    y,x = img.shape
    startx = x//2-(cropx//2)
    starty = y//2-(cropy//2)    
    img[starty:starty+cropy,startx:startx+cropx]=1
    return img

# create Noise image <---- copied from original post
distractor = visual.NoiseStim(
win=win, name='distractor',units='pix',
noiseImage='Stimuli/cowLeftCropped.jpg', mask='none',
ori=0, pos=[0,0], size=(512,512), sf=None,
phase=0.0,
color=[1,1,1], colorSpace='rgb', opacity=1, blendmode='avg', contrast=1.0,
texRes=128, filter=None,
noiseType='Image', noiseElementSize=0.0625,
noiseBaseSf=8.0, noiseBW=1,
noiseBWO=30, noiseOri=0.0,
noiseFractalPower=0.0,noiseFilterLower=1.0,
noiseFilterUpper=8.0, noiseFilterOrder=0.0,
noiseClip=3.0, imageComponent='Phase', interpolate=False, depth=-2.0)

#build the noise 
distractor.buildNoise()

#generate custom alpha mask using np array (values range from -1 to 1)
x1, y1 = 512, 512 #original dimensions
x2, y2 = 416, 315 #new dimensions
a = 0-np.ones([x1, y1])
custom_mask = crop_center(a, x2, y2)

#apply the mask
distractor.setMask(custom_mask)

#draw the image
distractor.draw()
win.flip()

#save the current screen
win.getMovieFrame()
win.saveMovieFrames("Stimuli/noiseStim.png")

core.wait(1)

```

Hopefully does what you need 🙂  
Becca

---

_[View the full topic](https://discourse.psychopy.org/t/builder-noisestim-to-imagestim/16146)._
