- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
OpenCV Python Program to blur an image?
OpenCV is one of the best python package for image processing. Also like signals carry noise attached to it, images too contain different types of noise mainly from the source itself (Camera sensor). Python OpenCV package provides ways for image smoothing also called blurring. This is what we are going to do in this section. One of the common technique is using Gaussian filter (Gf) for image blurring. With this, any sharp edges in images are smoothed while minimizing too much blurring.
Syntax
cv.GaussianBlur(src, ksize, sigmaX[, dst[, sigmaY[, borderType=BORDER_DEFAULT]]] )
Where−
src – input image
dst – output image
ksize – Gaussian kernel size[ height width]. If ksize is set to [0 0], then ksize is computed from sigma values.
sigmaX – Kernel standard deviation along X-axis(horizontal direction).
sigmaY – kernel standard deviation along Y-axis(Vertical direction).
Bordertype – Specifies iage boundaries while kernel is applied on image borders. Few possible values are: cv.BORDER_CONSTANT, cv.BORDER_REPLICATE, cv.BORDER_REFLECT, cv.BORDER_WRAP, cv.BORDER_DEFAULT, cv.BORDER_ISOLATED, cv.BORDER_TRANSPARENT etc.
Below is the program to Gaussian blur an image using OpenCV package.
import cv2 import numpy # read image src = cv2.imread('LionKing.jpeg', cv2.IMREAD_UNCHANGED) # apply guassian blur on src image dst = cv2.GaussianBlur(src,(3,3),cv2.BORDER_DEFAULT) # display input and output image cv2.imshow("Gaussian Blur",numpy.hstack((src, dst))) cv2.waitKey(0) # waits until a key is pressed cv2.destroyAllWindows() # destroys the window showing image
Result
The two images looks almost similar (original/blur). Now let us increase the kernel size and observe the result.
dst = cv2.GaussianBlur(src,(13,13),cv2.BORDER_DEFAULT)
Now there is a clear distinction between the two images.
- Related Articles
- How to blur faces in an image using OpenCV Python?
- Blurring an image using the OpenCV function blur()
- Blurring an image using the OpenCV function Gaussian Blur()
- How to blur an image using Node Jimp blur() function?
- Python Program to detect the edges of an image using OpenCV
- How to read an image in Python OpenCV?
- How to flip an image in OpenCV Python?
- How to mask an image in OpenCV Python?
- How to normalize an image in OpenCV Python?
- How to rotate an image in OpenCV Python?
- OpenCV Python – How to add borders to an image?
- How to convert an RGB image to HSV image using OpenCV Python?
- Reading an image using Python OpenCv module
- Cartooning an Image using OpenCV in Python?
- How to resize an image in OpenCV using Python?
