Different Image Denoising techniques in Computer Vision (original) (raw)

Last Updated : 15 Jun, 2026

Image denoising is a fundamental step in computer vision used to enhance image quality by reducing unwanted noise while preserving important details such as edges, textures, and structures. It plays a key role in improving the reliability of image-based analysis and decision-making systems.

**Types of Noise

Different denoising methods are designed based on the type of noise present in an image.

Common Techniques

1. Gaussian Filter

Gaussian filter is a linear smoothing technique that reduces noise by replacing each pixel with a weighted average of its neighboring pixels. The weights follow a Gaussian distribution, giving more importance to closer pixels. It is mainly used to reduce Gaussian noise but may slightly blur sharp edges.

**Code Implementation: A Gaussian blur is applied using OpenCV’s built-in function to reduce noise and smooth the image.

You can download the input image from here.

Python `

import cv2 import numpy as np

image = cv2.imread('noisy_image.jpg', cv2.IMREAD_GRAYSCALE)

sigma = 1.5 gaussian_denoised = cv2.GaussianBlur(image, (5, 5), sigma)

cv2.imwrite('gaussian_denoised.jpg', gaussian_denoised)

`

**Output:

gaussian_denoised

Gaussian Denoised

The resulting image shows reduced Gaussian noise with a smoother appearance.

2. Median Filter

Median filter is a non-linear technique that replaces each pixel with the median value of its surrounding neighborhood. It is especially effective for removing salt-and-pepper noise, where random black and white pixels appear in the image.

**Code Implementation: A median filter is applied to reduce impulse noise using a small kernel size.

Python `

kernel_size = 3
median_denoised = cv2.medianBlur(image, kernel_size)

cv2.imwrite('median_denoised.jpg', median_denoised)

`

**Output:

median_denoised

The output image effectively removes salt-and-pepper noise while preserving important edges.

3. Non-Local Means (NLM)

Non-Local Means is an advanced filtering technique that reduces noise by searching for similar pixel patterns across the entire image rather than limiting to a small neighborhood. It assigns higher weights to more similar patches, resulting in better preservation of textures and fine details.

**Code Implementation: NLM denoising is applied using OpenCV’s fast implementation.

Python `

nlm_denoised = cv2.fastNlMeansDenoising(image, h=10, templateWindowSize=7, searchWindowSize=21)

cv2.imwrite('nlm_denoised.jpg', nlm_denoised)

`

**Output:

nlm_denoised

Non-local means denoised

The denoised image retains fine textures while effectively reducing noise.

4. Convolutional Neural Networks (CNNs)

CNN-based denoising models learn how noise behaves by training on pairs of noisy and clean images. Instead of manually defining filters, the network automatically learns hierarchical features that help reconstruct clean images from noisy inputs.

**Code Implementation: DnCNN architecture is defined using convolutional and batch normalization layers.

Python `

import tensorflow as tf from tensorflow.keras import layers, Model

def dncnn(): inputs = layers.Input(shape=(None, None, 1))

x = layers.Conv2D(64, kernel_size=(3, 3), strides=(1, 1), padding='same')(inputs)
x = layers.ReLU()(x)

for _ in range(15):
    x = layers.Conv2D(64, kernel_size=(3, 3), strides=(1, 1), padding='same')(x)
    x = layers.BatchNormalization()(x)
    x = layers.ReLU()(x)

outputs = layers.Conv2D(1, kernel_size=(3, 3), strides=(1, 1), padding='same')(x)

model = Model(inputs, outputs)
return model

import cv2 import numpy as np

image = cv2.imread('noisy_image.jpg', cv2.IMREAD_GRAYSCALE) image = image.astype('float32') / 255.0 image = np.expand_dims(image, axis=0) image = np.expand_dims(image, axis=-1)

model = dncnn()

denoised_image = model.predict(image) denoised_image = np.squeeze(denoised_image) * 255.0 denoised_image = denoised_image.astype('uint8')

cv2.imwrite('dncnn_denoised.jpg', denoised_image)

`

**Output:

median_denoised

The model produces a denoised image by learning and removing complex noise patterns.

5. Generative Adversarial Networks (GANs)

GAN-based denoising uses two competing networks where the generator creates clean images and the discriminator evaluates their authenticity. Over time, this adversarial process helps generate highly realistic and visually sharp denoised images.

**Code Implementation: A simple CNN-based generator is used for denoising images from a URL.

Python `

import cv2 import numpy as np import requests from io import BytesIO from PIL import Image import tensorflow as tf

def build_denoiser_model(): generator = tf.keras.models.Sequential([

    tf.keras.layers.Conv2D(64, (3, 3), strides=(1, 1), padding='same', activation='relu', input_shape=(None, None, 1)),
    tf.keras.layers.Conv2D(64, (3, 3), strides=(1, 1), padding='same', activation='relu'),
    tf.keras.layers.Conv2D(1, (3, 3), strides=(1, 1), padding='same', activation='sigmoid')
])

return generator

def gan_denoise_image(image_url, denoiser_model): response = requests.get(image_url) noisy_image = Image.open(BytesIO(response.content)) noisy_image = np.array(noisy_image) noisy_image = np.expand_dims(noisy_image, axis=-1) / 255.0

denoised_image = denoiser_model.predict(np.expand_dims(noisy_image, axis=0))
denoised_image = np.squeeze(denoised_image) * 255.0
denoised_image = denoised_image.astype(np.uint8)

return denoised_image

image_url = 'https://raw.githubusercontent.com/cszn/DnCNN/master/testsets/Set12/01.png'

denoiser_model = build_denoiser_model()

denoised_image = gan_denoise_image(image_url, denoiser_model)

cv2.imwrite('denoised_image.jpg', denoised_image)

`

**Output:

denoised_image

The final image is highly realistic with significantly reduced noise and preserved details.

The complete source code can be downloaded from here.