Python | Denoising of colored images using opencv
Last Updated :
11 Aug, 2025
Images often contain unwanted noise due to poor lighting, low-quality sensors or high ISO settings. This noise can affect further image processing tasks such as edge detection, segmentation or object recognition
Denoising is a crucial pre-processing step that reconstructs a clean signal from a noisy image, helping improve analysis such as edge detection, segmentation and object recognition.
Function Used
Before diving into code, let’s understand core function we’ll be using for noise removal.
fastNlMeansDenoisingColored()
This function removes noise from RGB images using Non-Local Means algorithm. It averages similar patches to reduce grain while preserving edges and textures ideal for improving low-light or noisy photos.
Syntax
cv2.fastNlMeansDenoisingColored(src, dst, h, hColor, templateWindowSize, searchWindowSize)
Parameters:
- src: Input noisy colored image (as a NumPy array).
- dst: Output image (set None to return it directly).
- h: Filter strength for the luminance (brightness) component. Higher value means stronger smoothing.
- hColor: Same as h, but for color components. Not used for grayscale images.
- templateWindowSize: Size of the patch used for calculating weights.
- searchWindowSize: Size of the window to search for similar patches.
Example: Denoising a Noisy Image
This example shows how to denoise a color image using OpenCV’s fastNlMeansDenoisingColored() function. It removes noise while preserving details and displays original and denoised images side by side using Matplotlib.
Python
# Importing required libraries
import numpy as np
import cv2
from matplotlib import pyplot as plt
# Reading the noisy image from file
img = cv2.imread('bear.png')
# Applying denoising filter
dst = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 15)
# Displaying original and denoised images
plt.subplot(121), plt.imshow(img), plt.title('Original Image')
plt.subplot(122), plt.imshow(dst), plt.title('Denoised Image')
plt.show()
Output
Output of above exampleExplanation: cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 15): Applies non-local means denoising to color image img and stores the result in dst.
- img: Input noisy color image.
- None: Output image (created internally).
- 10: Strength for luminance denoising.
- 10: Strength for color denoising.
- 7: Size of template patch.
- 15: Size of search window.
Explore
Python Fundamentals
Python Data Structures
Advanced Python
Data Science with Python
Web Development with Python
Python Practice