Skip to content

Instantly share code, notes, and snippets.

@lindemann09
Created September 28, 2017 12:09
Show Gist options
  • Save lindemann09/a46f61502753f3c9e655d48a4d6093a8 to your computer and use it in GitHub Desktop.
Save lindemann09/a46f61502753f3c9e655d48a4d6093a8 to your computer and use it in GitHub Desktop.
Idea: Gabor Patch without matplotlib dependency
import expyriment
import numpy as np
expyriment.control.set_develop_mode()
exp = expyriment.control.initialize()
expyriment.control.start(skip_ready_screen=True)
def canvas_with_gabor_patch(sigma,theta,Lambda,psi,gamma):
sigma_x = sigma
sigma_y = float(sigma)/gamma
# Bounding box
nstds = 3
xmax = max(abs(nstds*sigma_x*np.cos(theta)),abs(nstds*sigma_y*np.sin(theta)))
xmax = np.ceil(max(1,xmax))
ymax = max(abs(nstds*sigma_x*np.sin(theta)),abs(nstds*sigma_y*np.cos(theta)))
ymax = np.ceil(max(1,ymax))
xmin = -xmax
ymin = -ymax
(x,y) = np.meshgrid(np.arange(xmin,xmax+1),np.arange(ymin,ymax+1 ))
(y,x) = np.meshgrid(np.arange(ymin,ymax+1),np.arange(xmin,xmax+1 ))
# Rotation
x_theta=x*np.cos(theta)+y*np.sin(theta)
y_theta=-x*np.sin(theta)+y*np.cos(theta)
pattern = np.exp(-.5*(x_theta**2/sigma_x**2+y_theta**2/sigma_y**2))*np.cos(2*np.pi/Lambda*x_theta+psi)
# make numpy pixel array
tmp = (np.ones(pattern.shape) * (255 / 2.0) * pattern) + (255 / 2.0)
pixel_array = np.ones((3, tmp.shape[1], tmp.shape[0])) * tmp.T
#make stimulus
stim = expyriment.stimuli.Canvas(pattern.shape)
stim.set_surface(pixel_array.T)
return stim
s = canvas_with_gabor_patch(sigma=55,theta=np.pi/2.9,Lambda=12.5,psi=120,gamma=1.)
s.present()
exp.keyboard.wait()
expyriment.control.end()
@lindemann09
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment