def test_numpyFilterMask(self): """if the mask is passed in as a numpy array it goes through a different set of rules when turned into a texture. But the outcome should be as above """ win = self.win from psychopy import filters gaussMask = filters.makeMask(128, 'gauss') size = numpy.array([2.0,2.0])*self.scaleFactor fileName = os.path.join(utils.TESTS_DATA_PATH, 'testimage.jpg') image = visual.ImageStim(win, image=fileName, mask=gaussMask, size=size, flipHoriz=True, flipVert=True) image.draw() utils.compareScreenshot('imageAndGauss_%s.png' %(self.contextName), win) win.flip()
For this they should be square arrays, with size in powers of two (e.g. 64,128,256,512) A 256x256 array can then be given color efficiently using the normal stimulus methods. A 256x256x3 array has its color defined by the array (obviously). This demo creates a radial array as a patch stimulus, using helper functions from psychopy.filters and then creates a second sub-stimulus created from a section of the original. Both are masked simply by circles. """ win = visual.Window([800,600], units='pix') #generate the radial textures cycles=6 res=512 radius = filters.makeRadialMatrix(res) radialTexture = np.sin(radius*2*np.pi*cycles) mainMask = filters.makeMask(res) #select the upper left quadrant of our radial stimulus radialTexture_sub = radialTexture[256:,0:256] #and create an appropriate mask for it subMask = filters.makeMask(res, radius=0.5, center=[-0,0]) bigStim = visual.GratingStim(win, tex=radialTexture, mask=mainMask, color=[1,1,1], size=512, sf=1.0/512, interpolate=True) #draw the quadrant stimulus centred in the top left quadrant of the 'base' stimulus (so they're aligned) subStim = visual.GratingStim(win, tex=radialTexture_sub, pos=(-128,128), mask=subMask, color=[1,1,1], size=256, sf=1.0/256, interpolate=True, autoLog=False)#this stim changes too much for autologging to be useful bigStim.draw() subStim.draw()
For this they should be square arrays, with size in powers of two (e.g. 64,128,256,512) A 256x256 array can then be given color efficiently using the normal stimulus methods. A 256x256x3 array has its color defined by the array (obviously). This demo creates a radial array as a patch stimulus, using helper functions from psychopy.filters and then creates a second sub-stimulus created from a section of the original. Both are masked simply by circles. """ win = visual.Window([800, 600], units='pix') #generate the radial textures cycles = 6 res = 512 radius = filters.makeRadialMatrix(res) radialTexture = np.sin(radius * 2 * np.pi * cycles) mainMask = filters.makeMask(res) #select the upper left quadrant of our radial stimulus radialTexture_sub = radialTexture[256:, 0:256] #and create an appropriate mask for it subMask = filters.makeMask(res, radius=0.5, center=[-0, 0]) bigStim = visual.GratingStim(win, tex=radialTexture, mask=mainMask, color=[1, 1, 1], size=512, sf=1.0 / 512, interpolate=True) #draw the quadrant stimulus centred in the top left quadrant of the 'base' stimulus (so they're aligned) subStim = visual.GratingStim(
def makeFilteredNoise(res, radius, shape='gauss'): noise = np.random.random([res, res]) kernel = filters.makeMask(res, shape='gauss', radius=radius) filteredNoise = filters.conv2d(kernel, noise) filteredNoise = ((filteredNoise-filteredNoise.min())/(filteredNoise.max()-filteredNoise.min())*2-1) return filteredNoise
# print i # print sample(range(nImages),5) factorsList = data.createFactorialTrialList(factors={'change_type': change_types, 'trial_probe_ecc':ecc_list, 'trial_probe_angle':angle_list}) #print 'factorsList: %g'%len(factorsList) #mainTrials=mainTrials+factorsList shuffle(mainTrials) trials = data.TrialHandler(nReps=1.0, method='random', extraInfo=expInfo, trialList=factorsList) thisExp.addLoop(trials) print 'Total trials: %g'%trials.nTotal aperture=visual.Rect(win=win,width=1, height=1, fillColor='red', units='norm') gaussTexture = filters.makeMask(196, shape='gauss') invGaussTexture = -gaussTexture #make opaq->transp and vice versa def replicate(a, xy, se, n): rptIdx = np.ones(a.shape[0 if xy == 'X' else 1], dtype=int) rptIdx[0 if se == 'start' else -1] = n + 1 return np.repeat(a, rptIdx, axis=0 if xy == 'X' else 1) #print np.shape(invGaussTexture) invGaussTexture = replicate(invGaussTexture,'X','start',30) invGaussTexture = replicate(invGaussTexture,'X','end',30) invGaussTexture = replicate(invGaussTexture,'Y','start',30) invGaussTexture = replicate(invGaussTexture,'Y','end',30)
"show_probe_on_target": [0, 1, 1, 1], } ) # print 'factorsList: %g'%len(factorsList) # mainTrials=mainTrials+factorsList # shuffle(mainTrials) trials = data.TrialHandler(nReps=1, method="random", extraInfo=expInfo, trialList=factorsList) thisExp.addLoop(trials) print "Total trials: %g" % trials.nTotal aperture = visual.Rect(win=win, width=1, height=1, fillColor="red", units="norm") gaussTexture = filters.makeMask(196, shape="gauss") invGaussTexture = -gaussTexture # make opaq->transp and vice versa def replicate(a, xy, se, n): rptIdx = np.ones(a.shape[0 if xy == "X" else 1], dtype=int) rptIdx[0 if se == "start" else -1] = n + 1 return np.repeat(a, rptIdx, axis=0 if xy == "X" else 1) # print np.shape(invGaussTexture) invGaussTexture = replicate(invGaussTexture, "X", "start", 30) invGaussTexture = replicate(invGaussTexture, "X", "end", 30) invGaussTexture = replicate(invGaussTexture, "Y", "start", 30)