Blur an image with OpenCV

Add a soft-focus effect by blurring the image. Use the GaussianBlue() function to blur an image. Let us see an example of blurring an image with OpenCV:

The following is the output:

Blur an image with OpenCV
Explanation:

This Python script demonstrates how to use the OpenCV library to load an image, apply a Gaussian blur, and display the result:

  • The script starts by importing OpenCV and loading an image from the specified file path using the cv2.imread() function.
  • The loaded image is assigned to the variable image.
  • A Gaussian blur is then applied to the image using the cv2.GaussianBlur() function. This function takes three arguments: the image to be blurred, the size of the kernel (15, 15) (which determines the level of blurriness), and the standard deviation in the X and Y directions (set to 0 to allow automatic calculation).
  • The blurred image is stored in the variable blurred_image.
  • Finally, the script displays the blurred image in a window titled “Blur Filter” using the cv2.imshow() function.
  • To allow interaction, the script waits for a key press with cv2.waitKey(0) before closing the window using cv2.destroyAllWindows().
  • This provides a clear and interactive way to visualize the blurred effect on the image.

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

Apply Sepia Tone filter with OpenCV
Edge Detection with OpenCV
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading