Skip to content

Commit

Permalink
function for getting angle at each point
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisVincent committed Nov 14, 2022
1 parent 628cca8 commit 91c702f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions stimuli/components/angular.py
@@ -0,0 +1,36 @@
import numpy as np

from stimuli.utils import resolution


def img_angles(visual_size=None, ppd=None, shape=None):
"""Matrix of angle (relative to center) for each pixel
Parameters
----------
visual_size : Sequence[Number, Number], Number, or None (default)
visual size [height, width] of image, in degrees
ppd : Sequence[Number, Number], Number, or None (default)
pixels per degree [vertical, horizontal]
shape : Sequence[Number, Number], Number, or None (default)
shape [height, width] of image, in pixels
Returns
-------
numpy.ndarray
array of shape, with the angle (in rad) relative to center point, for each pixel
"""

# Resolve resolution
shape, visual_size, ppd = resolution.resolve(shape, visual_size, ppd)

# Image coordinates
x = np.linspace(-visual_size.width / 2.0, visual_size.width / 2.0, shape.width)
y = np.linspace(-visual_size.height / 2.0, visual_size.height / 2.0, shape.height)
yy, xx = np.meshgrid(y, x)

# Rotate image coordinates
img_angles = -np.arctan2(xx, yy)
img_angles %= 2 * np.pi

return img_angles

0 comments on commit 91c702f

Please sign in to comment.