Blurring an image using the OpenCV function blur()

In this program, we will blur an image using the opencv function blur().


Step 1: Import OpenCV.
Step 2: Import the image.
Step 3: Set the kernel size.
Step 4: Call the blur() function and pass the image and kernel size as parameters.
Step 5: Display the results.

Original Image

Example Code

import cv2
image = cv2.imread("testimage.jpg")
kernel_size = (7,7)
image = cv2.blur(image, kernel_size)
cv2.imshow("blur", image)


Blurred Image


The kernel size is used to blur only a small part of an image. The kernel moves across the entire image and blurs the pixels it covers.