Open In App

OpenCV - Blur image

Last Updated : 06 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will learn how to Blur an image using Python OpenCV.


Python

</p><pre><code class="language-python3"># Python Program to blur image
import cv2 

# bat.jpg is the batman image.
img = cv2.imread('bat.jpg') 

# make sure that you have saved it in the same folder
# You can change the kernel size as you want
blurImg = cv2.blur(img,(10,10)) 
cv2.imshow('blurred image',blurImg)

cv2.waitKey(0)
cv2.destroyAllWindows()</code></pre><p></p><p><span>
</span></p><p dir="ltr"><span>       Output: </span></p><img src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/20201127104358/577.png" width="622" height="651"><p style="text-align: justify;" dir="ltr"><span>Now, this program above is using image blurring technique called </span><b><strong>Averaging.</strong></b><span>There are some other options available as well  </span><b><strong>Gaussian Blurring, Median Blurring, Bilateral Filtering.</strong></b><span> Lets make a couple of additions in our program and compare the results.</span></p><gfg-tabs data-run-ide="false" data-mode="light"><gfg-tab slot="tab">Python</gfg-tab><gfg-panel slot="panel" data-code-lang="python3"><pre><code class="language-python3">
# importing opencv CV2 module
import cv2 

# bat.jpg is the batman image.
img = cv2.imread('gfg.png')
 
# make sure that you have saved it in the same folder
# Averaging
# You can change the kernel size as you want
avging = cv2.blur(img,(10,10))
 
cv2.imshow('Averaging',avging)
cv2.waitKey(0)

# Gaussian Blurring
# Again, you can change the kernel size
gausBlur = cv2.GaussianBlur(img, (5,5),0) 
cv2.imshow('Gaussian Blurring', gausBlur)
cv2.waitKey(0)

# Median blurring
medBlur = cv2.medianBlur(img,5)
cv2.imshow('Media Blurring', medBlur)
cv2.waitKey(0)

# Bilateral Filtering
bilFilter = cv2.bilateralFilter(img,9,75,75)
cv2.imshow('Bilateral Filtering', bilFilter)
cv2.waitKey(0)
cv2.destroyAllWindows()

Original Image:

Averaging:

Gaussian Blurring:

Media Blurring:

Bilateral Filtering:


How to Blur an Image using OpenCV?
Visit Course explore course icon
Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy