How to blur an image in OpenCV Python

share link

by ganesh dot icon Updated: Jul 25, 2023

technology logo
technology logo

Solution Kit Solution Kit  

Digital image processing uses image blurring. It helps in removing graining from an image, improving the quality of the image, and blurring the background. 


An open-source and free library of computer vision and machine learning methods is called OpenCV (Open-Source Computer Vision). It is employed in several procedures, including object identification, image stitching, and video stabilization. Although it is written in C++, it provides interfaces for other programming languages like Python, Java, and C#. OpenCV is frequently employed in academic and commercial projects and is available for Windows, Linux, and macOS. To make an image blurry, you can use the GaussianBlur() method of OpenCV.


OpenCV-Python uses Numpy, a highly efficient library for numerical operations with a MATLAB-like syntax. Numpy arrays are translated into and out of all OpenCV array forms. The GaussianBlur() function uses the Gaussian kernel. The height and width of the kernel should be a positive and an odd number. Then you must specify the X and Y directions, which are sigmaX and sigmaY, respectively. If only one is specified, both are considered the same.


Here is an example of how you might use this function to make an image blurry:

Fig 1: Preview of the output that you will get on running this code from your IDE


Code

In this solution, we use the GaussianBlur function of the Opencv library

  1. Copy the code using the "Copy" button above, and paste it in a Python file in your IDE.
  2. Modify the name, location of the image to be blurred in the code.
  3. Run the file to create a blurred image.

I hope you found this useful. I have added the link to dependent libraries, version information in the following sections.


I found this code snippet by searching for "make a blurred image using opencv" in kandi. You can try any such use case!

Dependent Libraries

opencv-pythonby opencv

Shell doticonstar image 3491 doticonVersion:72doticon
License: Permissive (MIT)

Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.

Support
    Quality
      Security
        License
          Reuse

            opencv-pythonby opencv

            Shell doticon star image 3491 doticonVersion:72doticon License: Permissive (MIT)

            Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.
            Support
              Quality
                Security
                  License
                    Reuse

                      If you do not have OpenCV that is required to run this code, you can install it by clicking on the above link and copying the pip Install command from the OpenCV page in kandi.


                      You can search for any dependent library on kandi like OpenCV.

                      Environment Tested

                      I tested this solution in the following versions. Be mindful of changes when working with other versions.

                      1. The solution is created in Python3.9.
                      2. The solution is tested on OpenCV-Python 4.5.4 version.

                      Using this solution, we are able to make blurred images using the OpenCV library in Python with simple steps. This process also facilities an easy to use, hassle free method to create a hands-on working version of code which would help us an image in Python.

                      Support

                      1. For any support on kandi solution kits, please use the chat
                      2. For further learning resources, visit the Open Weaver Community learning page.