Updated April 10, 2023
Introduction to OpenCV Gaussian Blur
The following article provides an outline for OpenCV Gaussian Blur. While dealing with the problems related to computer vision, sometimes it is necessary to reduce the clarity of the images or to make the images distinct and this can be done using low pass filter kernels among which Gaussian blurring is one of them which makes use of a function called Gaussian Blur() function to remove the noise from the image or to reduce the details from the image and the Gaussian Blur() function returns a blurred image and Gaussian blurring is widely used in preprocessing stages before building the models in machine learning or deep learning and in graphics software.
Syntax to define Gaussian Blur() function in OpenCV:
GaussianBlur(source_image, kernel_size, sigmaX)
Where,
- source_image is the image that is to be blurred using Gaussian Blur() function.
- kernel_size is the matrix representing the size of the kernel.
- sigmaX is a variable representing the standard deviation of Gaussian kernel in X direction and it is of type double.
Working of Gaussian Blur() in OpenCV
- In order to be able to reduce the clarity of images or to make the images distinct or to remove the noise from the images or to reduce the details from the images, we make use of Gaussian blurring.
- Gaussian Blurring makes use of a function called Gaussian Blur() function to reduce the clarity of images or to make the images distinct or to remove the noise from the images or to reduce the details from the images.
- The image that is to be blurred is read using imread() function.
- Then the image along with the matrix representing the size of the Gaussian kernel and standard deviation of Gaussian kernel is passed as the parameters to the Gaussian Blur() function.
- The Gaussian Blur() function blurs the image and returns the blurred image as the output.
Examples of OpenCV Gaussian Blur
Given below are the examples of OpenCV Gaussian Blur:
Example #1
OpenCV program in python to demonstrate Gaussian Blur() function to read the input image and apply Gaussian blurring on the image and then display the blurred image as the output on the screen.
Code:
# importing all the required modules
import numpy as np
import cv2 as cv
# reading the image that is to be blurred using imread() function
imageread = cv.imread('C:/Users/admin/Desktop/images/tree.jpg')
# applying GaussianBlur() function on the image to blur the image and display it as the output on the screen
resultimage = cv.GaussianBlur(imageread, (7, 7), 0)
cv.imshow('Blurred_image', resultimage)
cv.waitKey(0)
cv.destroyAllWindows()
Output:
In the above program, we are importing the required modules. Then we are reading the image that is to be blurred using imread() function. Then we are applying Gaussian Blur() function on the image to blur the image and display it as the output on the screen.
Example #2
OpenCV program in python to demonstrate Gaussian Blur() function to read the input image and apply Gaussian blurring on the image and then display the blurred image as the output on the screen.
Code:
# importing all the required modules
import numpy as np
import cv2 as cv
# reading the image that is to be blurred using imread() function
imageread = cv.imread('C:/Users/admin/Desktop/images/educba.jpg')
# applying GaussianBlur() function on the image to blur the image and display it as the output on the screen
resultimage = cv.GaussianBlur(imageread, (7, 7), 0)
cv.imshow('Blurred_image', resultimage)
cv.waitKey(0)
cv.destroyAllWindows()
Output:
In the above program, we are importing the required modules. Then we are reading the image that is to be blurred using imread() function. Then we are applying Gaussian Blur() function on the image to blur the image and display it as the output on the screen.
Example #3
OpenCV program in python to demonstrate Gaussian Blur() function to read the input image and apply Gaussian blurring on the image and then display the blurred image as the output on the screen.
Code:
# importing all the required modules
import numpy as np
import cv2 as cv
# reading the image that is to be blurred using imread() function
imageread = cv.imread('C:/Users/admin/Desktop/images/plane.jpg')
# applying GaussianBlur() function on the image to blur the image and display it as the output on the screen
resultimage = cv.GaussianBlur(imageread, (7, 7), 0)
cv.imshow('Blurred_image', resultimage)
cv.waitKey(0)
cv.destroyAllWindows()
Output:
In the above program, we are importing the required modules. Then we are reading the image that is to be blurred using imread() function. Then we are applying Gaussian Blur() function on the image to blur the image and display it as the output on the screen.
Example #4
OpenCV program in python to demonstrate Gaussian Blur() function to read the input image and apply Gaussian blurring on the image and then display the blurred image as the output on the screen.
Code:
# importing all the required modules
import numpy as np
import cv2 as cv
# reading the image that is to be blurred using imread() function
imageread = cv.imread('C:/Users/admin/Desktop/images/car.jpg')
# applying GaussianBlur() function on the image to blur the image and display it as the output on the screen
resultimage = cv.GaussianBlur(imageread, (7, 7), 0)
cv.imshow('Blurred_image', resultimage)
cv.waitKey(0)
cv.destroyAllWindows()
Output:
In the above program, we are importing the required modules. Then we are reading the image that is to be blurred using imread() function. Then we are applying Gaussian Blur() function on the image to blur the image and display it as the output on the screen.
Conclusion
In this article, we have seen the concept of Gaussian blurring using Gaussian Blur() function with corresponding programming examples and their outputs to demonstrate them.
Recommended Articles
We hope that this EDUCBA information on “OpenCV Gaussian Blur” was beneficial to you. You can view EDUCBA’s recommended articles for more information.