bundles / scipy 1.17.1 / scipy / signal / _signaltools / medfilt2d
function
scipy.signal._signaltools:medfilt2d
Signature
def medfilt2d ( input , kernel_size = 3 ) Summary
Median filter a 2-dimensional array.
Extended Summary
Apply a median filter to the input array using a local window-size given by kernel_size (must be odd). The array is zero-padded automatically.
Parameters
input: array_likeA 2-dimensional input array.
kernel_size: array_like, optionalA scalar or a list of length 2, giving the size of the median filter window in each dimension. Elements of
kernel_sizeshould be odd. Ifkernel_sizeis a scalar, then this scalar is used as the size in each dimension. Default is a kernel of size (3, 3).
Returns
out: ndarrayAn array the same size as input containing the median filtered result.
Notes
This is faster than medfilt when the input dtype is uint8, float32, or float64; for other types, this falls back to medfilt. In some situations, scipy.ndimage.median_filter may be faster than this function.
Array API Standard Support
medfilt2d has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ⛔ JAX ⚠️ no JIT ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
import numpy as np from scipy import signal x = np.arange(25).reshape(5, 5) x✓
signal.medfilt2d(x, kernel_size=5)
✓signal.medfilt2d(x)
✓signal.medfilt2d(x, kernel_size=[5,3])
✓signal.medfilt2d(x, kernel_size=[3,5])
✓See also
Aliases
-
scipy.signal.medfilt2d