AI Image Editing · · 3 min read

Gaussian Blur in OpenCV – How to Blur Images using Python

Learn how to use cv2.GaussianBlur in Python with OpenCV. Apply Gaussian blur to images by following this full tutorial, code examples and tips.

Illustration depicting how to use cv2.gaussianblur in python with opencv tutorial, examples and tip
Learn how to use cv2.GaussianBlur in Python with OpenCV. Code your gaussian blur using the best methods to get the best blurred images.

Gaussian Blur is one of the most common techniques for softening images and reducing noise. In this tutorial, we’ll walk you through how to apply Gaussian Blur using OpenCV with Python. We’ll also explore how it compares with other blur filters, explain what’s happening behind the scenes, and show how to use different kernel sizes like the 5x5 Gaussian kernel.

What Is Gaussian Blur?

Gaussian Blur is an image filter that uses a Gaussian function to smooth or blur images. It's particularly useful for reducing image noise and detail. Unlike simple averaging (box blur), Gaussian blur takes neighboring pixels into account with different weights, providing a more natural and visually pleasing result.

This type of blur is widely used in photo editing, computer vision, and machine learning pipelines. You can also try a Gaussian Blur Image Online tool if you want a quick and easy way to apply the effect without writing code.

Why Use Gaussian Blur?

Gaussian Blur has a wide range of applications:

How to Use cv2.GaussianBlur in Python

OpenCV provides a built-in method called cv2.GaussianBlur() to apply the effect.

Syntax:

cv2.GaussianBlur(src, ksize, sigmaX[, dst[, sigmaY[, borderType]]]) → dst

Example:

import cv2

# Load the image
image = cv2.imread('example.jpg'
)

# Apply Gaussian Blur with 5x5 kernel
blurred = cv2.GaussianBlur(image, (5, 5), 0
)

# Save or display the result
cv2.imwrite('blurred.jpg'
, blurred)

Understanding the Gaussian Blur Matrix

When you apply Gaussian Blur, OpenCV uses a Gaussian kernel matrix to perform convolution. The values in the matrix are determined by the Gaussian function:

G(x, y) = (1 / 2πσ²) * e^(-(x² + y²)/2σ²)

For a 5x5 Gaussian kernel, the matrix might look something like this (simplified):

[1 4 6 4 1]
[4 16 24 16 4]
[6 24 36 24 6]
[4 16 24 16 4]
[1 4 6 4 1]

This matrix is normalized so the sum equals 1, preserving brightness.

Bilateral Filter vs Gaussian Blur

Both Gaussian Blur and Bilateral Filter (OpenCV) are used to smooth images. However, bilateral filtering is edge-preserving, making it ideal for denoising while keeping edges sharp.

Gaussian Blur:

Bilateral Filter:

Example using bilateral filter in OpenCV:
blurred = cv2.bilateralFilter(image, 9, 75, 75)

What Is a Practical Method to Conceal Sensitive Information in a Python Script?

A common use case of cv2.GaussianBlur is to blur out sensitive regions like faces, text, or license plates in an image. You can crop the region of interest (ROI) and apply the blur only to that part:

x, y, w, h = 100, 100, 200, 50
roi = image[y:y+h, x:x+w]
blurred_roi = cv2.GaussianBlur(roi, (25, 25), 0)
image[y:y+h, x:x+w] = blurred_roi

This method is especially useful in AI moderation, journalism, and social media.

Looking for an easier way? Use an automatic Blur Filter online that applies blur to backgrounds, faces, or objects automatically.

Comparison: cv2 Blur vs cv2.GaussianBlur

OpenCV also provides a simple cv2.blur() function, which uses a normalized box filter. It's faster but not as visually appealing as Gaussian blur:

blurred = cv2.blur(image, (5, 5))

Featurecv2.blur()cv2.GaussianBlur()
Filter typeBoxGaussian
SmoothnessMediumHigh
Edge handlingBasicNatural
Use caseFast blurQuality blur

Tips for Better Gaussian Blur Results

Final Thoughts on cv2.GaussianBlur

Learning how to use Gaussian Blur in OpenCV gives you powerful tools for image manipulation, privacy protection, and creative design. Whether you're blurring for style or to conceal information, cv2.GaussianBlur is a versatile and essential function.

Need a fast, code-free solution? Try the Blur Image Online editor to anonymize with AI. You can quickly soften portraits with BlurMe’s blur face tool. For photographers, content creators, or developers mastering the Gaussian effect is a must.

Read next

Ready to try it out?

Try it out with your own video or photo.
Free yourself from the risks of ignoring others' privacy.

photo_studio_preview