Skip to main content
`Ctrl`+`K`

# `medianfilter`: Median filter

medfilt(data, kernel_size=3, bool conditional=False, mode='nearest', cval=0)

  Function computing the median filter of the given input. Behavior at boundaries: the algorithm is reducing the size of the window/kernel for pixels at boundaries (there is no mirroring).

  Not-a-Number (NaN) float values are ignored. If the window only contains NaNs, it evaluates to NaN.

  In event of an even number of valid values in the window (either because of NaN values or on image border in shrink mode), the highest of the 2 central sorted values is taken.

  Parameters:

    - data (numpy.ndarray) – the array for which we want to apply the median filter. Should be 1d or 2d.

    - kernel_size (For 1D should be an int for 2D should be a tuple or a list of (kernel_height, kernel_width)) – the dimension of the kernel.

    - conditional (bool) – True if we want to apply a conditional median filtering.

    - mode (str) – the algorithm used to determine how values at borders are determined: ‘nearest’, ‘reflect’, ‘mirror’, ‘shrink’, ‘constant’

    - cval – Value used outside borders in ‘constant’ mode

  Returns:

    the array with the median value for each pixel.

medfilt1d(data, kernel_size=3, bool conditional=False, mode='nearest', cval=0)

  Function computing the median filter of the given input.

  Behavior at boundaries: the algorithm is reducing the size of the window/kernel for pixels at boundaries (there is no mirroring).

  Not-a-Number (NaN) float values are ignored. If the window only contains NaNs, it evaluates to NaN.

  In event of an even number of valid values in the window (either because of NaN values or on image border in shrink mode), the highest of the 2 central sorted values is taken.

  Parameters:

    - data (numpy.ndarray) – the array for which we want to apply the median filter. Should be 1d.

    - kernel_size (int) – the dimension of the kernel.

    - conditional (bool) – True if we want to apply a conditional median filtering.

    - mode (str) – the algorithm used to determine how values at borders are determined: ‘nearest’, ‘reflect’, ‘mirror’, ‘shrink’, ‘constant’

    - cval – Value used outside borders in ‘constant’ mode

  Returns:

    the array with the median value for each pixel.

medfilt2d(image, kernel_size=3, bool conditional=False, mode='nearest', cval=0)

  Function computing the median filter of the given input. Behavior at boundaries: the algorithm is reducing the size of the window/kernel for pixels at boundaries (there is no mirroring).

  Not-a-Number (NaN) float values are ignored. If the window only contains NaNs, it evaluates to NaN.

  In event of an even number of valid values in the window (either because of NaN values or on image border in shrink mode), the highest of the 2 central sorted values is taken.

  Parameters:

    - data (numpy.ndarray) – the array for which we want to apply the median filter. Should be 2d.

    - kernel_size (For 1D should be an int for 2D should be a tuple or a list of (kernel_height, kernel_width)) – the dimension of the kernel.

    - conditional (bool) – True if we want to apply a conditional median filtering.

    - mode (str) – the algorithm used to determine how values at borders are determined: ‘nearest’, ‘reflect’, ‘mirror’, ‘shrink’, ‘constant’

    - cval – Value used outside borders in ‘constant’ mode

  Returns:

    the array with the median value for each pixel.