O'Reilly logo

Computer Vision with Python 3 by Saurabh Kapur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Median blur

OpenCV has the medianBlur() function, which takes the image and size of the kernel as input (positive odd number):

>>> import cv2>>> img = cv2.imread("image.jpg")>>> new_img = cv2.medianBlur(img,5)>>> cv2.imwrite("median_blur.jpg", new_img)>>> cv2.imshow("median_blur", new_img)

The following figure is the result of applying the median blur filter:

Figure 10: The original image is on the left and the output is on the right

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required