OpenCV Tutorial
Image Processing
Feature Detection and Description
Drawing Functions
Video Processing
Applications and Projects
Denoising is the process of removing noise from images. Noise can be caused by various sources like electronic interference in camera sensors, poor lighting conditions, or high ISO settings. OpenCV provides a method for denoising colored images using the Non-Local Means Denoising algorithm.
In this tutorial, we will explore how to denoise colored images using OpenCV:
pip install opencv-python
import cv2
image = cv2.imread('path_to_noisy_image.jpg')
Using the cv2.fastNlMeansDenoisingColored()
function.
denoised_image = cv2.fastNlMeansDenoisingColored(image, None, 10, 10, 7, 21)
Here:
None
implies that a new array will be created for the output.h
for luminance and hForColorComponents
for color images). Higher values will remove noise but also remove image details, producing a blurry image.templateWindowSize
(default value 7), should be odd and affects the performance linearly: greater templateWindowSize
means slower computation.searchWindowSize
(default value 21), must be odd. Greater values will make the algorithm work slower but will produce better results.You can display both the noisy and denoised images for comparison.
cv2.imshow('Noisy Image', image) cv2.imshow('Denoised Image', denoised_image) cv2.waitKey(0) cv2.destroyAllWindows()
cv2.imwrite('path_to_save_denoised_image.jpg', denoised_image)
The parameters for the denoising function (cv2.fastNlMeansDenoisingColored()
) can be tweaked based on the type and level of noise in the image. It might require some trial and error to get the best results.
For denoising grayscale images, OpenCV provides cv2.fastNlMeansDenoising()
.
OpenCV offers an efficient method to denoise colored images using the Non-Local Means algorithm. Proper parameter tuning can provide a balance between noise removal and preserving image details. This tool can be especially useful for post-processing images captured in low-light conditions or with high ISO settings.
Python Code for Denoising RGB Images in OpenCV:
import cv2 # Load colored image img = cv2.imread('colored_image.jpg') # Denoise using Non-Local Means denoised_img = cv2.fastNlMeansDenoisingColored(img, None, h=10, hColor=10, templateWindowSize=7, searchWindowSize=21) # Display the original and denoised images cv2.imshow('Original Image', img) cv2.imshow('Denoised Image', denoised_img) cv2.waitKey(0) cv2.destroyAllWindows()