cupyx.scipy.ndimage.generic_filter#

cupyx.scipy.ndimage.generic_filter(input, function, size=None, footprint=None, output=None, mode='reflect', cval=0.0, origin=0)[source]#

Compute a multi-dimensional filter using the provided raw kernel or reduction kernel.

Unlike the scipy.ndimage function, this does not support the extra_arguments or extra_keywordsdict arguments and has significant restrictions on the function provided.

Parameters:
  • input (cupy.ndarray) – The input array.

  • function (cupy.ReductionKernel or cupy.RawKernel) – The kernel or function to apply to each region.

  • size (int or sequence of int) – One of size or footprint must be provided. If footprint is given, size is ignored. Otherwise footprint = cupy.ones(size) with size automatically made to match the number of dimensions in input.

  • footprint (cupy.ndarray) – a boolean array which specifies which of the elements within this shape will get passed to the filter function.

  • output (cupy.ndarray, dtype or None) – The array in which to place the output. Default is is same dtype as the input.

  • mode (str) – The array borders are handled according to the given mode ('reflect', 'constant', 'nearest', 'mirror', 'wrap'). Default is 'reflect'.

  • cval (scalar) – Value to fill past edges of input if mode is 'constant'. Default is 0.0.

  • origin (scalar or tuple of scalar) – The origin parameter controls the placement of the filter, relative to the center of the current element of the input. Default of 0 is equivalent to (0,)*input.ndim.

Returns:

The result of the filtering.

Return type:

cupy.ndarray

Note

If the function is a cupy.RawKernel then it must be for a function that has the following signature. Unlike most functions, this should not utilize blockDim/blockIdx/threadIdx:

__global__ void func(double *buffer, int filter_size,
                     double *return_value)

If the function is a cupy.ReductionKernel then it must be for a kernel that takes 1 array input and produces 1 ‘scalar’ output.