Package psychopy :: Module filters
[frames] | no frames]

Module filters

source code

Various useful functions for creating filters and textures (e.g. for PatchStim)
Functions
 
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
source code
 
maskMatrix(matrix, shape='circle', radius=1.0, center=(0.0, 0.0))
Make and apply a mask to an input matrix (e.g.
source code
 
makeMask(matrixSize, shape='circle', radius=1.0, center=(0.0, 0.0))
Returns a matrix to be used as an alpha mask (circle,gauss,ramp)
source code
 
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
source code
 
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
source code
 
getRMScontrast(matrix)
Returns the RMS contrast (the sample standard deviation) of a array
source code
 
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
source code
 
imfft(X)
Perform 2D FFT on an image and center low frequencies
source code
 
imifft(X)
Inverse 2D FFT with decentering
source code
 
butter2d_lp(size, cutoff, n=3)
Create lowpass 2D Butterworth filter
source code
 
butter2d_bp(size, cutin, cutoff, n)
Bandpass Butterworth filter in two dimensions
source code
 
butter2d_hp(size, cutoff, n=3)
Highpass Butterworth filter in two dimensions
source code
 
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.
source code
Function Details

makeGrating(res, ori=0.0, cycles=1.0, phase=0.0, gratType='sin', contr=1.0)

source code 
Make an array containing a luminance grating of the specified params
Returns:
a square numpy array of size resXres

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)

maskMatrix(matrix, shape='circle', radius=1.0, center=(0.0, 0.0))

source code 
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 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)

makeMask(matrixSize, shape='circle', radius=1.0, center=(0.0, 0.0))

source code 
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) - 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)

makeRadialMatrix(matrixSize, center=(0.0, 0.0), radius=1.0)

source code 
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 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)

makeGauss(x, mean=0.0, sd=1.0, gain=1.0, base=0.0)

source code 
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

conv2d(smaller, larger)

source code 

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!)

butter2d_lp(size, cutoff, n=3)

source code 
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

butter2d_bp(size, cutin, cutoff, n)

source code 
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

butter2d_hp(size, cutoff, n=3)

source code 
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

butter2d_lp_elliptic(size, cutoff_x, cutoff_y, n=3, alpha=0, offset_x=0, offset_y=0)

source code 
Butterworth lowpass filter of any elliptical shape.
Parameters:
  • size (tuple) - size of the filter
  • cutoff_x, cutoff_y - 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 - 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