Guest User

Untitled

a guest
Jun 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def gabor_fn(sigma, theta, Lambda, psi, gamma):
  4. sigma_x = sigma
  5. sigma_y = float(sigma) / gamma
  6.  
  7. # Bounding box
  8. nstds = 3 # Number of standard deviation sigma
  9. xmax = max(abs(nstds * sigma_x * np.cos(theta)), abs(nstds * sigma_y * np.sin(theta)))
  10. xmax = np.ceil(max(1, xmax))
  11. ymax = max(abs(nstds * sigma_x * np.sin(theta)), abs(nstds * sigma_y * np.cos(theta)))
  12. ymax = np.ceil(max(1, ymax))
  13. xmin = -xmax
  14. ymin = -ymax
  15. (y, x) = np.meshgrid(np.arange(ymin, ymax + 1), np.arange(xmin, xmax + 1))
  16.  
  17. # Rotation
  18. x_theta = x * np.cos(theta) + y * np.sin(theta)
  19. y_theta = -x * np.sin(theta) + y * np.cos(theta)
  20.  
  21. gb = np.exp(-.5 * (x_theta ** 2 / sigma_x ** 2 + y_theta ** 2 / sigma_y ** 2)) * np.cos(2 * np.pi / Lambda * x_theta + psi)
  22. return gb
Add Comment
Please, Sign In to add comment