16-Remove Noise
Noise in digital images is more than just a nuisance — it can significantly affect the performance of your computer vision pipeline. Whether you're working with scanned documents, medical imagery, or photographs, reducing noise is often the first step in preprocessing.
In this tutorial, we'll take a close look at how to reduce noise using the Gaussian filter, a simple yet powerful image smoothing tool. You’ll learn how it works, how it differs from other filters, and how to implement it in both MATLAB and Python (OpenCV).
🔍 What Is Noise in Images?
Before we embark on our journey to remove noise, let’s first understand what noise in images entails. Noise can manifest in various forms, including random variations in pixel values, distortions introduced during image acquisition or transmission, or imperfections arising from the imaging sensor itself. Common types of noise include Gaussian noise, salt-and-pepper noise, and speckle noise, each posing unique challenges to image processing algorithms.
Noise refers to random variations in pixel intensity that can distort image quality. It usually appears due to poor lighting, faulty sensors, or data transmission errors. Common types include:
-
Gaussian noise – Normally distributed, random intensity shifts.
-
Salt-and-pepper noise – Sudden white or black pixel bursts.
-
Speckle noise – Granular noise often seen in ultrasound and radar images.
Each type of noise presents a unique challenge, and Gaussian filtering is especially effective at handling Gaussian noise.
Section 2- 🌡️ Meet the Gaussian Filter
The Gaussian filter, named after the Gaussian distribution, it employs, is a widely used linear filter for image smoothing and noise reduction. Unlike other filters that apply a uniform weighting to neighboring pixels, the Gaussian filter assigns higher weights to nearby pixels and lower weights to those farther away, resembling the shape of a Gaussian bell curve. This characteristic enables the Gaussian filter to effectively blur an image while preserving important details.
A Gaussian filter uses the properties of the Gaussian distribution (a bell curve) to smooth an image. Instead of averaging all neighboring pixels equally, it gives more weight to closer pixels and less to those farther away.
This makes it ideal for blurring an image gently without completely losing details — perfect for noise reduction.
Key Features:
-
Preserves edges better than box filters.
-
Reduces high-frequency noise.
-
Parameterized by kernel size and sigma (standard deviation).
Section 1- Remove Noise with Matlab
We discussed noise removal using a filter. Let's test the effectiveness of that approach. Let's load a perfectly good image.
# Remove noise with a Gaussian filter
%% Load an image
img=imread ('saturn.png')
imshow(img);

Spoil it by adding some noise. It would be wise to assign a name to this sigma to prevent any confusion in the future.
%% Add some noise
noise_sigma=25;
noise= randan(size(img)).*noise_sigma;
noisy_img=img+noise;
imshow(noisy_img);

 At last, we have understood the process of creating a Gaussian filter. We establish a size and a sigma.Then, the fspecial function from the image package can be utilized. Begin by loading the package.Then, proceed to create the filter.Now, this filter can be applied to eliminate noise. Note the order of parameters in imfilter. First is the image and second is the filter. Observe how the filter has created a smoother effect, or rather, blurred the image. The noise, which once had a fine, particle-like appearance, is now blurred.. But the filter has also affected the original image a great deal.
%% Create a Gaussian Filter
filter_size=11;
filter_sigma=2;
pkg load image;
filter = fspecial('gaussian',filter_size, filter_sigma);
 Indeed, noise removal is not magic. You do not receive precisely what you began with.. Visually, it may not appear very impressive., but image processing routines further down the road behave quite differently given a noisy image versus a smooth image. Go ahead and run this code yourself. Try out different parameters for noise generation and smoothing.
%% Apply it to remove noise
somoothed = imfilter(noisy_img, filter);
Section 2- Remove Noise with Python
import cv2
import numpy as np
# Load an image
img = cv2.imread('saturn.png')
# Add some noise
noise_sigma = 25
noise = np.random.randn(*img.shape) * noise_sigma
noisy_img = np.clip(img + noise, 0, 255).astype(np.uint8)
# Display noisy image
cv2.imshow('Noisy Image', noisy_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Create a Gaussian Filter
filter_size = 11
filter_sigma = 2
filter = cv2.getGaussianKernel(filter_size, filter_sigma)
filter = filter * filter.T
# Apply it to remove noise
smoothed = cv2.filter2D(noisy_img, -1, filter)
# Display smoothed image
cv2.imshow('Smoothed Image', smoothed)
cv2.waitKey(0)
cv2.destroyAllWindows()
🎯 Real-World Applications of Gaussian Filtering
Gaussian filters are everywhere in image processing and computer vision:
-
📸 Digital photography: Smoothing noisy photos before applying effects or enhancements.
-
🩺 Medical imaging: Reducing artifacts in MRI or CT scans.
-
🛰️ Satellite imagery: Enhancing Earth observation data before classification.
-
🤖 Computer vision: Preprocessing for edge detection, object detection, and segmentation.