medianfilter: OpenCL median filter

A module for performing the 1d, 2d and 3d median filter ...

The target is to mimic the signature of scipy.signal.medfilt and scipy.medfilt2

The first implementation targets 2D implementation where this operation is costly (~10s/2kx2k image)

class silx.opencl.medfilt.MedianFilter2D(shape, kernel_size=(3, 3), ctx=None, devicetype='all', platformid=None, deviceid=None, block_size=None, profile=False)[source]

A class for doing median filtering using OpenCL

set_kernel_arguments()[source]

Parametrize all kernel arguments

send_buffer(data, dest)[source]

Send a numpy array to the device, including the cast on the device if possible

Parameters:
  • data – numpy array with data
  • dest – name of the buffer as registered in the class
calc_wg(kernel_size)[source]

calculate and return the optimal workgroup size for the first dimension, taking into account the 8-height band

Parameters:kernel_size – 2-tuple of int, shape of the median window
Returns:optimal workgroup size
medfilt2d(image, kernel_size=None)[source]

Actually apply the median filtering on the image

Parameters:
  • image – numpy array with the image
  • kernel_size – 2-tuple if
Returns:

median-filtered 2D image

Nota: for window size 1x1 -> 7x7 up to 49 / 64 elements in 8 threads, 8elt/th
9x9 -> 15x15 up to 225 / 256 elements in 32 threads, 8elt/th 17x17 -> 21x21 up to 441 / 512 elements in 64 threads, 8elt/th

TODO: change window size on the fly,

static calc_kernel_size(kernel_size)[source]

format the kernel size to be a 2-length numpy array of int32