neurotools.signal.conv module

Helper routines for convolutions, mostly related to padding.

neurotools.signal.conv.reflect2D(data)[source]

Reflects 2D data for use with the discrete cosine transform.

Parameters:

data (np.array) – data may have dimensions (H,W) or (H,W,N)

Returns:

result – shape (2H,2W) array if data is 2D. shaoe (2H,2W,N) array if data is 3D.

Return type:

np.array

neurotools.signal.conv.reflect2D_1(data)[source]

Reflects 2D data, without doubling the data on the edge.

Parameters:

data (np.array) – data may have dimensions (H,W) or (H,W,N)

Returns:

result – shape (2H-2,2W-2) array if data is 2D. shaoe (2H-2,2W-2,N) array if data is 3D.

Return type:

np.array

neurotools.signal.conv.mirror2d(x)[source]

Mirror-pad a 2D signal to implement reflected boundary conditions for 2D convolution.

This function is obsolete and superseded by reflect2D().

Parameters:

X (2D np.array) – Signal to pad

neurotools.signal.conv.convolve2dct(x, k)[source]
neurotools.signal.conv.separable2d(X, k, k2=None)[source]

Convolve 2D signal X with two one-dimensional convolutions with kernel k.

This uses reflected boundary padding

Parameters:
  • X (2D np.array) – Signal to convolve

  • k (1D np.array) – Convolution kernel

  • k2 (1D np.array) – Convolution kernel for the section array dimension, if X is not square or if different horizontal and vertical kernels are desired.

Returns:

result – Convolved result

Return type:

2D np.array

neurotools.signal.conv.gausskern2d(sigma, size)[source]

Generate 2D Gaussian kernel

Parameters:
  • sigma (positive float) – Kernel standard deviation

  • size (positive int) – Size of kernel to generate

Returns:

kernel – Gaussian kernel

Return type:

2D np.float32

neurotools.signal.conv.gausskern1d(sigma, size)[source]

Generate 1D Gaussian kernel

Parameters:
  • sigma (positive float) – Kernel standard deviation

  • size (positive int) – Size of kernel to generate

Returns:

kernel – Gaussian kernel

Return type:

1D np.float32