Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Science
  • Data Science Projects
  • Data Analysis
  • Data Visualization
  • Machine Learning
  • ML Projects
  • Deep Learning
  • NLP
  • Computer Vision
  • Artificial Intelligence
Open In App
Next Article:
What are the different Image denoising techniques in computer vision?
Next article icon

What are the different Image denoising techniques in computer vision?

Last Updated : 04 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Image denoising techniques in computer vision are essential for enhancing the quality of images corrupted by noise, thereby improving the accuracy of subsequent image processing tasks. Noise in images can arise from various sources such as sensor limitations, transmission errors, or environmental factors. The goal of denoising techniques is to effectively remove unwanted noise while preserving the important details and structures in the image.

What is the Importance of Image Denoising?

Image denoising is important for several reasons:

  • Medical Imaging: Images must be clearer so that the doctors can make correct diagnosis.
  • Photography: Removing noise is especially important to enhance the quality of the photos, especially the ones shot at night or in any other low light environment.
  • Remote Sensing: This means that satellite images that are to be used in the analysis of geographical data have to be very sharp.
  • Surveillance: Improved image quality thus enables one to spot relative features in security tapes.
  • Automated Systems: That is why it is necessary to work on the improvement of the quality of the image, as systems such as self-driving cars and robots require good images.

Denoising is removing the noise from an image rendering the important features more visible and also increases the efficiency of the further data processing tasks.

Common Techniques of Image denoising

Now, we will discuss some methods of image denoising which are implemented.

Gaussian Filter

The Gaussian filter blurs the image as output is an average of the pixels value within the particular neighborhood with a weighting function of Gaussian distribution. This technique entailing much high-frequency noise, which are the fine details and edges, and reduce them to give a smoother image. The standard deviation (sigma) of the Gaussian function controls the level of smoothing:

  • Small sigma: They have less smoothing which retains more of the features and details of the objects and surfaces.
  • Large sigma: A little more smoothing, which is even capable to wash out the important features.

Code Implementation:

The provided Python code snippet demonstrates image denoising using OpenCV's GaussianBlur function. It reads a grayscale noisy image from 'noisy_image.jpg', applies a Gaussian filter with a kernel size of (5, 5) and a standard deviation (sigma) of 1.5, and saves the denoised image as 'gaussian_denoised.jpg'. Gaussian blur is effective for reducing Gaussian noise, smoothing the image while preserving edges and details to some extent.

Python
import cv2 import numpy as np  # Load a noisy image image = cv2.imread('noisy_image.jpg', cv2.IMREAD_GRAYSCALE)  # Apply Gaussian filter sigma = 1.5  # Standard deviation for Gaussian kernel gaussian_denoised = cv2.GaussianBlur(image, (5, 5), sigma)  # Save or display the result cv2.imwrite('gaussian_denoised.jpg', gaussian_denoised) 

Output:

gaussian_denoised
Gaussian Denoised


The output file 'gaussian_denoised.jpg' will contain the denoised version of the input image, where noise, particularly Gaussian noise, has been reduced, resulting in a cleaner and visually improved image suitable for further analysis or presentation.

Median Filter

The Median filter is a non-linear filter that replaces each pixel value with median value of the pixels in its neighborhood. This filter proves quite useful in the removal of salt-and-pepper noise which is characterized by isolated black and white speckles. The Median filter works well because:

Actually, it yields edges in better preservation than the Gaussian filter.

  • It can effectively filter out any noise particularly the outliers WHILE at the same time making sure that overall important features will not be lost.
  • The size of the neighborhood or the kernel by which we can increase or reduce defines the degree of noise removal or the degree of detail preservation.

Code Implementation:

The cv2.medianBlur function applies a median filter with a kernel size of 3x3 to the grayscale image. This filter replaces each pixel value with the median value of its neighboring pixels within the specified kernel size, effectively reducing salt-and-pepper noise in the image.

Python
# Apply Median filter kernel_size = 3  # Size of the neighborhood median_denoised = cv2.medianBlur(image, kernel_size)  # Save or display the result cv2.imwrite('median_denoised.jpg', median_denoised) 


Output:

median_denoised


Non-Local Means (NLM)

NLM is another enhanced denoising method, distinguishable from the simpler, straightforward local neighborhood parking scheme. It operates through applying the formula that divides the sum of all pixels’ values in the image by their corresponding weights, if the pixels are similar to the referenced pixel. Key features of NLM include:

  • Similarity Measure: Talking more of intensity value pixels are compared by the intensity values found in a certain window surrounding the said pixel.
  • Search Window: The region where similar pixels are looked for averaging to advance a shared procedure.

NLM gives excellent results in preserving vital features such as textures and fine details because it is able to search for similar patterns within the image.

Code Implementation:

The code snippet applies Non-Local Means (NLM) denoising to an image using OpenCV, a popular computer vision library. The function cv2.fastNlMeansDenoising is employed to reduce noise in the image, with parameters specifying the filtering strength (h=10), the size of the template patch (templateWindowSize=7), and the size of the search window (searchWindowSize=21). This advanced denoising technique preserves the image's fine details while effectively removing noise. After the denoising process, the result is saved as 'nlm_denoised.jpg' using cv2.imwrite, making the cleaned image available for further use or display. This method is particularly useful in scenarios where maintaining high image quality is crucial despite the presence of noise.

Python
# Apply Non-Local Means denoising nlm_denoised = cv2.fastNlMeansDenoising(image, h=10, templateWindowSize=7, searchWindowSize=21)  # Save or display the result cv2.imwrite('nlm_denoised.jpg', nlm_denoised) 


Output:

nlm_denoised
Non-local means denoised

Convolutional Neural Networks (CNNs)

CNNs, such as DnCNN, are trained to map from the noisy images to the clean ones. The SO features employ multiple layers of the convolutional filter, which is used to reconstruct image features and, therefore, minimize noises.

Code Implementation:

The provided code defines a deep learning model called DnCNN (Denoising Convolutional Neural Network) using TensorFlow and Keras, which is specifically designed for image denoising. The model consists of a sequence of convolutional layers, ReLU activation functions, and batch normalization layers to effectively learn and remove noise from images.

Python
import tensorflow as tf from tensorflow.keras import layers, Model  def dncnn():     inputs = layers.Input(shape=(None, None, 1))          # Initial convolutional layer     x = layers.Conv2D(64, kernel_size=(3, 3), strides=(1, 1), padding='same')(inputs)     x = layers.ReLU()(x)          # Middle convolutional layers     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)          # Final convolutional layer     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  # Load the noisy image 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)  # Create the DnCNN model model = dncnn()   # Denoise the image using the model denoised_image = model.predict(image) denoised_image = np.squeeze(denoised_image) * 255.0 denoised_image = denoised_image.astype('uint8')  # Save or display the result cv2.imwrite('dncnn_denoised.jpg', denoised_image) 

Output:
median_denoised

Generative Adversarial Networks (GANs)

There is always a generator and a discriminator network in case of GANs. The generator produces resultant clear images, on the other hand, the discriminator aims at distinguishing between the original and clear images. This way, GANs obtain highly realistic images that have been denoised during the described adversarial process. The identified methods of deep learning are convenient because they are capable to work with various patterns of noise and with different kinds of images.

Code Implementation:

The provided code sets up a simple GAN-based denoiser model using TensorFlow and Keras to clean a noisy image retrieved from a URL. The build_denoiser_model function defines a sequential generator model comprising three convolutional layers with ReLU activations and a final sigmoid activation to ensure the output remains in the [0, 1] range. The gan_denoise_image function fetches the noisy image from the URL, preprocesses it, and applies the denoiser model to predict and produce a cleaned image.

Python
import cv2 import numpy as np import requests from io import BytesIO from PIL import Image import tensorflow as tf  # Define the GAN-based denoiser model def build_denoiser_model():     # Define the generator model (denoiser)     generator = tf.keras.models.Sequential([         # Define layers of the generator (e.g., convolutional layers, activation functions)         # Example:         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  # Function to denoise image using the GAN model def gan_denoise_image(image_url, denoiser_model):     # Load the noisy image from URL     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          # Perform denoising using the GAN model     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  # URL of the noisy image image_url = 'https://raw.githubusercontent.com/cszn/DnCNN/master/testsets/Set12/01.png'  # Build the denoiser model denoiser_model = build_denoiser_model()  # Denoise the image using the GAN model denoised_image = gan_denoise_image(image_url, denoiser_model)  # Save or display the denoised image cv2.imwrite('denoised_image.jpg', denoised_image) 


Output:

denoised_image



Conclusion

Image denoising is considered as primal in the field of computer vision because it is critical for improving image quality and subsequent analysis. Some of the common techniques which are basic but efficient in nature are Gaussian, Median for a particular type of noise. More complex algorithms such as Non-Local Means and deep learning provide better denoising as they allow preserving small details and learning from complex noise. The selection of an appropriate denoising method depends on the type of noise and characteristics of the application, such as the level of detail that needs to be preserved and computational complexity.


Next Article
What are the different Image denoising techniques in computer vision?

H

hawk123
Improve
Article Tags :
  • Blogathon
  • Computer Vision
  • AI-ML-DS
  • Interview-Questions
  • Data Science Blogathon 2024

Similar Reads

    Image Thresholding Techniques in Computer Vision
    Image thresholding is a technique in computer vision that converts a grayscale image into a binary image by setting each pixel to either black or white based on a specific threshold value. The article provides a comprehensive overview of various image thresholding techniques used in computer vision,
    7 min read
    What are the main steps in a typical Computer Vision Pipeline?
    Computer vision is a field of artificial intelligence (AI) that enables machines to interpret and understand the visual world. By using digital images from cameras and videos and deep learning models, machines can accurately identify and classify objects — and then react to what they “see.” A comput
    4 min read
    Noise Removing Technique in Computer Vision
    Noise is random variations in pixel values that distort an image often caused by factors like sensor imperfections, low-light conditions, etc. For example, photos taken in low light may appear grainy due to this noise. Effective noise reduction enhances feature extraction by making edges and texture
    7 min read
    Image Segmentation Approaches and Techniques in Computer Vision
    Image segmentation partitions an image into multiple segments that simplify the image's representation, making it more meaningful and easier to work with. This technique is essential for various applications, from medical imaging and autonomous driving to object detection and image editing. Effectiv
    7 min read
    What are some common loss functions used in training computer vision models?
    In the field of computer vision, training effective models hinges on the choice of appropriate loss functions. These functions serve as critical components that guide the learning process by quantifying the difference between the predicted outputs and the actual target values. Selecting the right lo
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences