psychopy.filters - helper functions for creating filters
Various useful functions for creating filters and textures (e.g. for PatchStim)
-
psychopy.filters.butter2d_bp(size, cutin, cutoff, n)
Bandpass Butterworth filter in two dimensions
Parameters: |
- size : tuple
size of the filter
- cutin : float
relative cutin frequency of the filter (0 - 1.0)
- cutoff : float
relative cutoff frequency of the filter (0 - 1.0)
- n : int, optional
order of the filter, the higher n is the sharper
the transition is.
|
Returns: |
- numpy.ndarray
filter kernel in 2D centered
|
-
psychopy.filters.butter2d_hp(size, cutoff, n=3)
Highpass Butterworth filter in two dimensions
Parameters: |
- size : tuple
size of the filter
- cutoff : float
relative cutoff frequency of the filter (0 - 1.0)
- n : int, optional
order of the filter, the higher n is the sharper
the transition is.
|
Returns: |
- numpy.ndarray:
filter kernel in 2D centered
|
-
psychopy.filters.butter2d_lp(size, cutoff, n=3)
Create lowpass 2D Butterworth filter
Parameters: |
- size : tuple
size of the filter
- cutoff : float
relative cutoff frequency of the filter (0 - 1.0)
- n : int, optional
order of the filter, the higher n is the sharper
the transition is.
|
Returns: |
- numpy.ndarray
filter kernel in 2D centered
|
-
psychopy.filters.butter2d_lp_elliptic(size, cutoff_x, cutoff_y, n=3, alpha=0, offset_x=0, offset_y=0)
Butterworth lowpass filter of any elliptical shape.
Parameters: |
- size : tuple
size of the filter
- cutoff_x, cutoff_y : float, float
relative cutoff frequency of the filter (0 - 1.0) for x and y axes
- alpha : float, optional
rotation angle (in radians)
- offset_x, offset_y : float
offsets for the ellipsoid
- n : int, optional
order of the filter, the higher n is the sharper
the transition is.
|
Returns: |
- numpy.ndarray:
filter kernel in 2D centered
|
-
psychopy.filters.conv2d(smaller, larger)
convolve a pair of 2d numpy matrices
Uses fourier transform method, so faster if larger matrix
has dimensions of size 2**n
Actually right now the matrices must be the same size (will sort out
padding issues another day!)
-
psychopy.filters.getRMScontrast(matrix)
Returns the RMS contrast (the sample standard deviation) of a array
-
psychopy.filters.imfft(X)
Perform 2D FFT on an image and center low frequencies
-
psychopy.filters.imifft(X)
Inverse 2D FFT with decentering
-
psychopy.filters.makeGauss(x, mean=0.0, sd=1.0, gain=1.0, base=0.0)
Return the gaussian distribution for a given set of x-vals
Parameters: |
- mean: float
the centre of the distribution
- sd: float
the width of the distribution
- gain: float
the height of the distribution
- base: float
an offset added to the result
|
-
psychopy.filters.makeGrating(res, ori=0.0, cycles=1.0, phase=0.0, gratType='sin', contr=1.0)
Make an array containing a luminance grating of the specified params
Parameters: |
- res: integer
the size of the resulting matrix on both dimensions (e.g 256)
- ori: float or int (default=0.0)
the orientation of the grating in degrees
- cycles:float or int (default=1.0)
the number of grating cycles within the array
- phase: float or int (default=0.0)
the phase of the grating in degrees (NB this differs to most
PsychoPy phase arguments which use units of fraction of a cycle)
- gratType: ‘sin’, ‘sqr’, ‘ramp’ or ‘sinXsin’ (default=”sin”)
the type of grating to be ‘drawn’
- contr: float (default=1.0)
contrast of the grating
|
Returns: | a square numpy array of size resXres
|
-
psychopy.filters.makeMask(matrixSize, shape='circle', radius=1.0, center=(0.0, 0.0), range=[-1, 1], fringeWidth=0.2)
Returns a matrix to be used as an alpha mask (circle,gauss,ramp)
Parameters: |
- matrixSize: integer
the size of the resulting matrix on both dimensions (e.g 256)
- shape: ‘circle’,’gauss’,’ramp’ (linear gradient from center),
‘raisedCosine’ (the edges are blurred by a raised cosine)
shape of the mask
- radius: float
scale factor to be applied to the mask (circle with radius of
[1,1] will extend just to the edge of the matrix). Radius can
asymmetric, e.g. [1.0,2.0] will be wider than it is tall.
- center: 2x1 tuple or list (default=[0.0,0.0])
the centre of the mask in the matrix ([1,1] is top-right corner,
[-1,-1] is bottom-left)
- fringeWidth: float (0-1)
The proportion of the raisedCosine that is being blurred.
- range: 2x1 tuple or list (default=[-1,1])
The minimum and maximum value in the mask matrix
|
-
psychopy.filters.makeRadialMatrix(matrixSize, center=(0.0, 0.0), radius=1.0)
Generate a square matrix where each element val is
its distance from the centre of the matrix
Parameters: |
- matrixSize: integer
the size of the resulting matrix on both dimensions (e.g 256)
- radius: float
scale factor to be applied to the mask (circle with radius of
[1,1] will extend just to the edge of the matrix). Radius can
be asymmetric, e.g. [1.0,2.0] will be wider than it is tall.
- center: 2x1 tuple or list (default=[0.0,0.0])
the centre of the mask in the matrix ([1,1] is top-right
corner, [-1,-1] is bottom-left)
|
-
psychopy.filters.maskMatrix(matrix, shape='circle', radius=1.0, center=(0.0, 0.0))
Make and apply a mask to an input matrix (e.g. a grating)
Parameters: |
- matrix: a square numpy array
array to which the mask should be applied
- shape: ‘circle’,’gauss’,’ramp’ (linear gradient from center)
shape of the mask
- radius: float
scale factor to be applied to the mask (circle with radius of
[1,1] will extend just to the edge of the matrix). Radius can
be asymmetric, e.g. [1.0,2.0] will be wider than it is tall.
- center: 2x1 tuple or list (default=[0.0,0.0])
the centre of the mask in the matrix ([1,1] is top-right
corner, [-1,-1] is bottom-left)
|