Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
function for getting angle at each point
- Loading branch information
1 parent
628cca8
commit 91c702f
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |