13.1 Convolution functions

boxcar( data, boxshape, output=None, mode='nearest', cval=0.0)
boxcar computes a 1-D or 2-D boxcar filter on every 1-D or 2-D subarray of data. boxshape is a tuple of integers specifying the dimensions of the filter, e.g. (3,3). If output is specified, it should be the same shape as data and the result will be stored in it. In that case None will be returned.

mode can be any of the following values:

nearest
: Elements beyond boundary come from nearest edge pixel.
wrap
: Elements beyond boundary come from the opposite array edge.
reflect
: Elements beyond boundary come from reflection on same array edge.
constant
: Elements beyond boundary are set to what specified in cval, an optional numerical parameter; the default value is 0.0.
>>> print a
[1 5 4 7 2 9 3 6]
>>> print conv.boxcar(a,(3,))
[ 2.33333333  3.33333333  5.33333333  4.33333333  6.          4.66666667
  6.          5.        ]
# for even number box size, it will take the extra point from the lower end
>>> print conv.boxcar(a,(2,))
[ 1.   3.   4.5  5.5  4.5  5.5  6.   4.5]

convolve( data, kernel, mode=FULL)
Returns the discrete, linear convolution of 1-D sequences data and kernel; mode can be VALID, SAME, or FULL to specify the size of the resulting sequence. See section 13.2.

convolve2d( data, kernel, output=None, fft=0, mode='nearest', cval=0.0)
Return the 2-dimensional convolution of data and kernel. If output is not None, the result is stored in output and None is returned. fft is used to switch between FFT-based convolution and the naive algorithm, defaulting to naive. Using fft mode becomes more beneficial as the size of the kernel grows; for small kernels, the naive algorithm is more efficient. mode has the same choices as those of boxcar.

correlate( data, kernel, mode=FULL)
Return the cross-correlation of data and kernel; mode can be VALID, SAME, or FULL to specify the size of the resulting sequence. See section 13.2.

correlate2d( data, kernel, output=None, fft=0, mode='nearest', cval=0.0)
Return the 2-dimensional convolution of data and kernel. If output is not None, the result is stored in output and None is returned. fft is used to switch between FFT-based convolution and the naive algorithm, defaulting to naive. Using fft mode becomes more beneficial as the size of the kernel grows; for small kernels, the naive algorithm is more efficient. mode has the same choices as those of boxcar.

Note: cross_correlate is deprecated and should not be used.

Send comments to the NumArray community.