Sunday, November 19, 2023

OpenCV and Image Processing - Blur Image (Median Blur)

Same as Gaussian Blur, the Median Blur is also widely used in image processing, it is often used for noise reduction purposes. Similar to the Gaussian Blur filter, instead of applying Gaussian formula, the Median Blur calculates the median of all the pixels inside the kernel filter and the central pixel is replaced with this median value. OpenCV also provides a function for this purpose, cv2.medianBlur().

Here is the code in ImageProcessing class to apply the median blur function, 

1 def median_blur(self, ksize=1, image=None):

2 if image is None:

3 image = self.image

4 result = cv2.medianBlur(image, ksize)

5 return result

In BlurImage.py file the codes for Median Blur are quite similar to the Gaussian Blur, a trackbar can change the kernel size, and the effects can be observed in real time. Below shows the original image vs. the median-blurred image.



Share:

0 comments:

Post a Comment