Scikit Image - Denoising an Image



Denoising an image refers to the process of reducing or removing noise from a digital image. Noise in an image typically appears as random variations in brightness or color that are not part of the original scene or subject being photographed. The goal of image denoising is to enhance the quality of an image by eliminating or reducing these unwanted and distracting artifacts, making the image cleaner, and more visually appealing.

The Scikit Image library offers a range of denoising filters for image processing, allowing users to remove noise from noisy images and recover the original image. In this tutorial, we will explore three different denoising filters provided by Scikit Image −

Total Variation Filter (skimage.restoration.denoise_tv_chambolle())

The total variation filter aims to minimize the total variation norm of the image while maintaining its similarity to the original. Total variation is essentially the L1 norm of the image's gradient.

Bilateral Filter (skimage.restoration.denoise_bilateral())

The bilateral filter is designed to preserve edges while reducing noise. It considers both spatial proximity and radiometric similarity when averaging pixel values.

Wavelet Denoising Filter (skimage.restoration.denoise_wavelet())

This filter relies on the wavelet representation of the image. It identifies noise as small values in the wavelet domain and sets them to zero. This filter is especially effective at reducing noise while preserving image details.

In color images, wavelet denoising is often performed in the YCbCr color space to avoid introducing more noticeable noise in individual color channels.

To illustrate the effectiveness of these denoising filters(total variation, bilateral, and wavelet denoising), we'll apply them to a noisy image.

Example

The following example demonstrates the application of total variation, bilateral, and wavelet denoising filters on a noisy image.

import matplotlib.pyplot as plt
from skimage.restoration import (denoise_tv_chambolle, denoise_bilateral, denoise_wavelet, estimate_sigma)
from skimage import io, img_as_float
from skimage.util import random_noise

# Load an input image
original = img_as_float(io.imread('Images/hand writting.jpg'))

# Add Gaussian noise to create a noisy version of the image.
sigma = 0.155
noisy = random_noise(original, var=sigma**2)

# Estimate the average noise standard deviation across color channels.
sigma_est = estimate_sigma(noisy, channel_axis=-1, average_sigmas=True)
print(f'Estimated Gaussian noise standard deviation = {sigma_est}')

# Create a figure with a 2x4 grid for displaying images.
fig, axes = plt.subplots(nrows=2, ncols=4, figsize=(10,5), sharex=True, sharey=True)
ax0, ax1, ax2, ax3, ax4, ax5, ax6, ax7 = axes.ravel()
plt.gray()

# Display the noisy image.
ax0.imshow(noisy)
ax0.set_title('Noisy')

# Apply Total Variation (TV) denoising with a specified weight
ax1.imshow(denoise_tv_chambolle(noisy, weight=0.1, channel_axis=-1))
ax1.set_title('TV')

# Apply Bilateral denoising with specified sigma parameters.
ax2.imshow(denoise_bilateral(noisy, sigma_color=0.05, sigma_spatial=15, channel_axis=-1))
ax2.set_title('Bilateral')

# Apply Wavelet denoising.
ax3.imshow(denoise_wavelet(noisy, channel_axis=-1, rescale_sigma=True))
ax3.set_title('Wavelet denoising')

# Display the original image 
ax4.imshow(original)
ax4.set_title('Original') 

# Apply TV denoising with a different weight.
ax5.imshow(denoise_tv_chambolle(noisy, weight=0.2, channel_axis=-1))
ax5.set_title('(more) TV')

# Apply Bilateral denoising with different sigma parameters.
ax6.imshow(denoise_bilateral(noisy, sigma_color=0.1, sigma_spatial=15, channel_axis=-1))
ax6.set_title('(more) Bilateral')

# Apply Wavelet denoising in the YCbCr colorspace.
ax7.imshow(denoise_wavelet(noisy, channel_axis=-1, convert2ycbcr=True, rescale_sigma=True))
ax7.set_title('Wavelet denoising\nin YCbCr colorspace')

for ax in axes.flat:
   ax.axis('off')
    
fig.tight_layout()
plt.show()

Output

Estimated Gaussian noise standard deviation = 0.1415983008453029
denoising image
Advertisements