Image.medianfilter#
- Image.medianfilter(h: int = 1, **kwargs: Any) Any[source]#
Median filter
- Parameters:
h (int, optional) – half width of structuring element, defaults to 1
kwargs – options passed to
rankfilter
- Returns:
median filtered image
- Return type:
Imageinstance
Return the median filtered image. For every \(w \times w, w=2h+1\) window take the median value as the output pixel value.
Example:
>>> from machinevisiontoolbox import Image >>> import numpy as np >>> array = np.arange(25).reshape((5,5)) >>> array[2, 2] = 0 >>> img = Image(array) >>> img.print() 0 1 2 3 4 5 6 7 8 9 10 11 0 13 14 15 16 17 18 19 20 21 22 23 24 >>> img.medianfilter(h=1).print() # median filter 1 2 3 4 4 5 5 6 7 9 10 10 11 13 14 15 16 17 18 19 20 20 21 22 23 >>> img = Image.Read('monalisa.png') >>> img.medianfilter(h=5).disp() # ameliorate background cracking <matplotlib.image.AxesImage object at 0x7f076e0046e0>
Note
This filter is effective for removing impulse (aka salt and pepper) noise.
- References:
P. Corke, Robotics, Vision & Control for Python, Springer, 2023, Section 11.5.3.
- Seealso: