Median filtering

OpenCV provides the cv2.medianBlur() function, which blurs the image with a median kernel, as shown in the following code:

smooth_image_mb = cv2.medianBlur(image, 9)

This filter can be applied to reduce the salt-and-pepper noise of an image.