This is a very simple filter that returns the median value from the pixel and its neighbors. Both pillow and skimage provide built-in functions for this filter.
The following code sample applies a median filter over an image using pillow:
>>> from PIL import Image>>> from PIL import ImageFilter>>> img = Image.open("image.png")>>> blur_img = img.filter(ImageFilter.MedianFilter(7))>>> blur_img.show()
Similarly, using skimage, the following code applies a median filter to a given image:
>>> from skimage import io>>> from skimage import filters>>> img = io.imread("image.png")>>> out = filters.median(img, disk(7))>>> io.imshow(out)>>> io.show()