Python | cv2 GaussianBlur() Method

In this tutorial, we will see how to Blurring an image in python programming language using open-cv, which exists as a cv2 (computer vision) library in python.

You can use GaussianBlur() method of cv2 library to blur an image. In order to use cv2 library, you need to import cv2 library using import statement. You can read about more about Gaussian function

The blurring of an image means smoothening of an image i.e., removing outlier pixels that may be noise in the image.

Now let’s see the syntax and return value of GaussianBlur() method, then we will move on the examples.

Syntax

Parameters

  1. src: Source/Input of n-dimensional array.
  2. ksize: Kernal is matrix of an (no. of rows)*(no. of columns) order .Its Size is given in the form of tuple (no. of rows, no. of columns). no. of rows and no. of columns should be odd .If ksize is given as (0 0), then ksize is computed from given sigma values i.e. sigmaX and sigmaY.
  3. sigmaX: Standard deviation value of kernal along horizontal direction.
  4. sigmaY: Standard deviation value of kernal along vertical direction.
  5. borderType: This specify boundaries of an image while kernel is applied on borders of an image.
  6. Possible values of borderType are :

    1. cv2.BORDER_CONSTANT
    2. cv2.BORDER_REPLICATE
    3. cv2.BORDER_REFLECT
    4. cv2.BORDER_WRAP
    5. cv2.BORDER_REFLECT_101
    6. cv2.BORDER_TRANSPARENT
    7. cv2.BORDER_REFLECT101
    8. cv2.BORDER_DEFAULT
    9. cv2.BORDER_ISOLATED

Return Value

It returns Output blurred image of n-dimensional array.

a) In GaussianBlur() method, you need to pass src and ksize values everytime and either one, two, or all parameters value from remaining sigmax, sigmaY and borderType parameter should be passed.

b) Both sigmaX and sigmaY parameters become optional if you mention the ksize(kernal size) value other than (0,0).

cv2 GaussianBlur() Method example

Now Let’s see the Python code :

Example 1: Using GaussianBlur() method with src,ksize and borderType parameters.

Output :

Output1

Example 2: Using GaussianBlur() method with src,ksize and sigmaX parameters.

Output :

Output2

You may similarly change the values of other properties and observe the outputs.
That’s all about cv2 GaussianBlur() Method in Python.

Related Posts

  • Convert image to grayscale in Python
    21 August

    Convert image to grayscale in python

    Table of ContentsUsing the .convert() function from the Pillow Imaging Library (Fork) to convert image to grayscale in Python.Using the OpenCV library functions to convert image to grayscale in Python.Using the color.rgb2gray() function from the scikit-image module to convert image to grayscale in Python.Using the Conversion Formula along with the matplotlib library to convert image […]

  • Rotate image Python
    20 August

    Rotate image in Python

    Table of ContentsUsing the image.rotate() function from the Pillow Imaging Library (Fork) to rotate image in Python.Using NumPy library functions to rotate image in Python.Using the OpenCV and imutils library functions to rotate image in Python.Using matplotlib and SciPy libraries to rotate image in Python. Python supports the use of images and sometimes a given […]

  • 09 August

    Python | Introduction and Installation of OpenCv

    Table of ContentsIntroductionComputer Vision1) Acquiring an image2) Processing the image3) Understanding the imageApplications1) Sports – Hawk Eye2) Smart carsOpenCVInsall openCV on windows and linuxDownloading and Installing OpenCV: In this tutorial, we are learning about what is OpenCv and how OpenCV is installed in windows/linux system. Introduction Have you ever seen Facebook’s auto-tag feature? Whenever you […]

  • 09 August

    Python | cv2 imshow() Method

    Table of ContentsSyntaxParametersReturn ValueReturn value In this tutorial, we will see how to display an image as an output using python by the use of open-cv which is exist as cv2 (computer vision) library. We can use imshow() method of cv2 library to display an image in a window. In order to use cv2 library, […]

  • 09 August

    Python | cv2 imwrite() Method

    Table of ContentsSyntaxParametersReturn Valuecv2 imwrite() method Examples In this tutorial, we will see how to save an image in your own system using python by using open-cv which exists as cv2 (computer vision) library. You can use imwrite() method of cv2 library to save an image on your system. To use cv2 library, you need […]

  • 23 May

    Python | cv2 findContours() Method

    Table of ContentsSyntaxParametersReturn ValueContours Approximation Methodcv2 findContours() Method examplesExample 1: Using cv2.RETR_TREE as a retrieval mode and cv2.CHAIN_APPROX_NONE as a Contour approximation method.Example 2: Using cv2.RETR_EXTERNAL as a Contour retrieval mode and cv2.CHAIN_APPROX_SIMPLE as a Contour approximation method.Reference In this tutorial, we will see how to find all boundary points(x,y) of an object in the […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.