machinevisiontoolbox.Image.medianfilter

Image.medianfilter(h=1, **kwargs)

Median filter

Parameters:
  • h (int, optional) – half width of structuring element, defaults to 1

  • kwargs – options passed to rank

Returns:

median filtered image

Return type:

Image instance

Return the median filtered image. For every \(w \times w, w=2h+1\) window take the median value as the output pixel value.

Example:

  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/machinevisiontoolbox/ImageSpatial.py", line 1287, in rank
    out = sp.ndimage.rank_filter(
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/scipy/ndimage/_filters.py", line 1543, in rank_filter
    return _rank_filter(input, rank, size, footprint, output, mode, cval,
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/scipy/ndimage/_filters.py", line 1454, in _rank_filter
    raise RuntimeError('footprint array has incorrect shape.')
RuntimeError: footprint array has incorrect shape.
Note:

This filter is effective for removing impulse (aka salt and pepper) noise.

References:
  • Robotics, Vision & Control for Python, Section 11.5.3, P. Corke, Springer 2023.

Seealso:

rank