Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Unlock the full potential of AI with Building LLMs for Productionβ€”our 470+ page guide to mastering LLMs with practical projects and expert insights!

Publication

Reconstruction of Clean Images from Noisy Data: A Bayesian Inference Perspective
Data Science   Latest   Machine Learning

Reconstruction of Clean Images from Noisy Data: A Bayesian Inference Perspective

Last Updated on October 19, 2024 by Editorial Team

Author(s): Bhavesh Agone

Originally published on Towards AI.

An Introduction to Bayesian Analysis

In its most basic form, Bayesian Inference is just a technique for summarizing statistical inference which states how likely an hypothesis is given any new evidence. The method comes from Bayes’ Theorem, which provides a way to calculate the probability that an event will happen or has happened, given any prior knowledge of conditions (from which an event may not happen):

Here’s a somewhat rough rendering of Bayes’ Theorem:

Where:
– P(A|B) refer to the posterior probability, that is the probability of the hypothesis (A) given data (B).
– P(B|A) is the probability, or how likely the obtained data is in case the hypothesis is correct.
– P(A) is the prior probability or our starting starting point in regard to the hypothesis in question before making use of the sample data.
– P(B) Probability of the data or otherwise known as the evidence.

Bayesian Inference in the most simple method possible can be described as a method that lets us start with some sort of a belief about something- the prior β€” and then modify that belief based on new information that is received in terms of the likelihood. Bayesian method is thus particularly suitable for uncertainty and incomplete data, such as signal reconstruction from noise.

It is named after an 18th-century mathematician, Thomas Bayes.

The Challenge: Noisy Data in Image Reconstruction

Noise in images is a common problem in a variety of fields:
Some images will fail to reveal clarity due to:

– Medical Imaging: Some CT scans, MRIs, or X-rays are distorted with artefacts generated by the movement of patients during the scan time, hardware resolution limit, or it simply has low resolution.

– Satellite Imagery: At one point, images captured by satellites have been distorted due to atmospheric conditions, sensor limitation, or motion blur, thus making the satellite images not as helpful for environmental monitoring or navigation purposes.

– Astronomy: Sometimes, clearest views of celestial objects are distorted by noise from the telescopes themselves and interference from Earth’s atmosphere.

It is a rather difficult task to reconstruct a clean, original image using noisy data. Convolutional filtering directly applied to the noisy data normally removes the noise but also leads to the loss of important details or introduction of various artifacts.

Bayes Approach to Image Reconstruction

This is where Bayesian Inference comes into the picture. The Bayesian approach to image reconstruction works by combining everything that you may already know about the image-for instance, that edges tend to be smooth or that certain features ought to be continuous-with the noisy data we observe. It tries to find a most likely β€œclean” image that may have lead to what we see as noisy, given your prior assumptions.

  1. Prior knowledge: It is then used in Bayesian image reconstruction in order to model what we expect the clean image to look like beforehand. For example, natural images tend to be smooth in some parts and high in edges in other parts.
  2. Likelihood: The likelihood function maps the noisy image into the clean image, and with that, it captures how the noise affects the image-for instance, Gaussian noise might blur the image.
  3. Posterior Distribution: By Bayes’ Theorem, we combine the prior and the likelihoods to yield a posterior distribution that now supplies us with a probability distribution over possible clean images. We look for the image maximizing this posterior probability by what is called the MAP estimate.
  4. Markov Chain Monte Carlo (MCMC): In practice, it is often not easy to find the posterior distribution; therefore, the use of Markov Chain Monte Carlo (MCMC) techniques to sample from the distribution, estimating the most probable clean image, is very common.

Example of Bayesian Image Denoising

In this implementation, lets see a method for improving image structure using a combination of Gaussian noise simulation and Bayesian methods. We first add Gaussian noise to grayscale images to simulate a noisy environment. as the noise reduction process uses confidence propagation to refine noisy images and reproduce the message. This is supplemented with global normalization (TV), non-local noise reduction (NLM), and wavelet thresholding to improve image quality by preserving essential features and edges. and the final result will be saved and displayed. which demonstrates the effectiveness of this multifaceted noise reduction technique.

#Importing necesssary libaries for denoising Image using Bayersain
import numpy as np
import cv2
from scipy.fft import fft2, ifft2
from skimage.restoration import denoise_tv_chambolle, denoise_wavelet, denoise_nl_means
from skimage.util import random_noise
from skimage import img_as_float, img_as_ubyte
# Define parameters for noise level, belief propagation, and denoising iterations

sigma2_init = 25 # Initial variance of noise
alpha_init = 0.01 # Initial alpha parameter
max_iterations = 20 # Maximum iterations for the EM algorithm
convergence_threshold = 1e-4 # Convergence threshold for belief propagation
# Function to add Gaussian noise to an image
# This simulates noise in the image for testing denoising techniques

def add_gaussian_noise(image, sigma):
noisy_image = image + np.random.normal(0, sigma, image.shape)
return np.clip(noisy_image, 0, 255)
# Function to compute belief propagation messages with adaptive convergence
# It calculates messages iteratively using Fourier transforms until convergence

def compute_messages(image, alpha, sigma2, prev_messages=None):
height, width = image.shape
messages = np.zeros((height, width)) if prev_messages is None else prev_messages
fft_image = fft2(image)

for _ in range(max_iterations):
fft_messages = fft2(messages)
new_messages = ifft2(fft_image * fft_messages * alpha).real
new_messages = np.clip(new_messages, 0, 255) # Clip to valid pixel range

# Check for convergence based on L2 norm
if np.linalg.norm(new_messages - messages) < convergence_threshold:
break

messages = new_messages
return messages
# Function for denoising using belief propagation and multiple advanced denoising methods
# This includes Total Variation (TV) regularization, Non-Local Means (NLM), and wavelet denoising

def bayesian_denoise(image, noisy_image, alpha, sigma2, max_iterations):
denoised_image = np.copy(noisy_image)
messages = None

for _ in range(max_iterations):
# Compute belief propagation messages
messages = compute_messages(denoised_image, alpha, sigma2, prev_messages=messages)

# Update the denoised image based on messages
denoised_image = (noisy_image + messages) / 2
denoised_image = np.clip(denoised_image, 0, 255)

# Apply Total Variation (TV) denoising to preserve edges
denoised_image = denoise_tv_chambolle(denoised_image, weight=0.1)

# Apply Non-Local Means (NLM) denoising for further noise reduction
denoised_image = denoise_nl_means(denoised_image, h=1.15 * sigma2, fast_mode=True)

# Optionally apply wavelet-based denoising
denoised_image = denoise_wavelet(denoised_image, mode='soft', wavelet_levels=3, method='BayesShrink')

return denoised_image
# Load the image, convert it to grayscale, and apply Gaussian noise to simulate a noisy image

image_path = "img_2.png"
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE).astype(np.float32)

# Add Gaussian noise to simulate a noisy image
noisy_image = add_gaussian_noise(image, sigma=25)
# Perform Bayesian denoising on the noisy image using the specified techniques
denoised_image = bayesian_denoise(image, noisy_image, alpha_init, sigma2_init, max_iterations)
# Save and display the results
cv2.imwrite("denoised_image_enhanced.jpg", denoised_image)
cv2.imshow("Noisy Image", noisy_image.astype(np.uint8))
cv2.imshow("Denoised Image", denoised_image.astype(np.uint8))sssss
cv2.waitKey(0)
cv2.destroyAllWindows()

Results:

Noisy vs Denoised Image

PSNR (Peak Signal-to-Noise Ratio) is a widely used metric for measuring the quality of reconstructed or processed images. Compare with the original unchanged image. Especially in image compression work. deterioration and restoration to assess where smearing or distortion occurred during processing.

Computation Time vs Image Size & PSNR vs Image Size

Application: Medical Image Recovery

One of the most fascinating applications of Bayesian Inference is in medical imaging, where recovered clean images are crucial for diagnosis.

For example, suppose that a CT scan has been degraded by noise due to either motion by the patient or hardware constraints. A Bayesian framework can take this noisy scan as observed data and prior knowledge of typical body structure-the smoothness of edges or regular organ shapes-to reconstruct the original, clean image. This is particularly useful in Bayesian tomography, where the goal is to reconstruct the 3D structure of an object-which might look like a human body-from noisy 2D images.

In this way, the outputs of several noisy scans are taken and, with Bayesian methods, high-resolution, noise-free images which are much more helpful to doctors can be recovered. Hereby, the chance for an accurate diagnosis is maximized while minimizing scans that otherwise may be expensive or even dangerous through radiation.

Bayesian Inverse Problems: Satellite Image Reconstruction

Another interesting application of Bayesian image reconstruction is in satellite imagery. Satellites are often taking photographs under suboptimal conditions. For example, cloudy weather, low-light environments, or poor weather can often lead to noisy images that are either hard to interpret or carry information with undefined reliability.

Bayesian Inference solves the problem, modeling the noise and using prior knowledge about the Earth’s surface in order to infer the most likely clean image. For example, we know that some areas of land, such as oceans or deserts, tend to have smooth textures, whereas urban areas have sharp, well-defined edges. Then by using the Bayesian framework, we can reconstruct a clean image to look much like the real landscape even after noisy data.

This application proves very useful in monitoring changes brought by the environment, tracking cut-down forest, or even damage assessment brought by natural disasters that require timely and accurate images from space.

Benefits of Bayesian Image Reconstruction

Probability approach. Unlike other methods, Bayesian Inference provides a probabilistic estimate of the clean image, so uncertainty in reconstruction could be quantified. That is the value when dealing with applications like medicine where knowing the confidence level of an image can help in making decisions.
Prior Information Incorporation: Bayesian methods allow for the utilisation of prior knowledge about the image, which results in more accurate reconstructions. For example, in medical imaging, we may use prior information about typical anatomical structures to guide the reconstruction process.

– Versatility: The Bayesian approach can be adapted to a wide range of imaging problems, from medical scans to satellite photos, thus making it a versatile tool for solving image reconstruction problems in different domains.

Bayesian inference allows for robust frameworks in dealing with noisy reconstructions of data. We, therefore, infer a most likely clean image from noisy observations by combining prior knowledge that we have about the image. Bayesian methods are thus very important in all applications, ranging from medical imaging to satellite imaging, because they are flexible and accurate in cleaning up noisy data.

With the progress in computational technology, such as MCMC, together with better algorithms, Bayesian methods will be even more easily applied and result in improved performance over the classic reconstruction methods of images.

Whatever the application area-medical, environmental monitoring, or astronomy- Bayesian Inference might turn to be the tool to extract valuable information from noisy and sparse data, leading to increasing insight and, therefore, better decision making.

Please feel free to share your thoughts in the comment section. Your suggestions are always welcome.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.

Published via Towards AI

Feedback ↓