Image Processing Tutorial Using scikit-image - Noise

Betul Mescioglu

Smoothing Edges in an Image: Gaussian Filter

Applying a Gaussian filter reduces the image's high frequency components. Thus, it is called a low pass filter. It is often used to remove Gaussian (random) noise from the image. Skimage.filters module has a function called gaussian() that employs this feature on images. It takes a parameter called sigma that determines how much of the noise will be removed. Larger sigma values may remove more noise, but they will also remove more details from the image.

#Importing necessary libraries
import matplotlib.pyplot as plt
import skimage.filters
from skimage.util import random_noise 
from skimage.restoration import denoise_tv_chambolle, denoise_bilateral

#Loading the image
candy ='candy.jpg')
#Displaying the image
plt.title('Original Image')
(-0.5, 899.5, 719.5, -0.5)

Let's apply a Gaussian filter to the candy image:

gauss_blurred = skimage.filters.gaussian(candy, sigma=(3,3), truncate=3.5,multichannel=True)
plt.title('Gaussian Filter Applied Image')
(-0.5, 899.5, 719.5, -0.5)

We observe that the sharpness of the image is reduced and colors blend in more.

Adding Noise to an Image:

We can add noise to an image using skimage. Here, we will add random noise to a landscape image using Gaussian, Salt & Pepper and Poisson distributions.

#Adding noise to an image:
land ='land.jpg')
#Add Gaussian noise:
g_noised_image = random_noise(land, mode='gaussian')
#Add salt&pepper noise:
sp_noised_image = random_noise(land, mode='s&p', amount=0.09)
#Add Poisson noise:
poisson_noised_image =random_noise(land, mode='poisson')
#Plot all noised images with the original image:
fig, ax = plt.subplots(nrows=2,ncols=2, figsize=(12,6), sharex=True, sharey=True, squeeze=True)
ax = ax.ravel()
ax[0].set_title('Original Image')
ax[1].set_title('Noise Added Image (Gaussian)')
ax[2].set_title('Noise Added Image (Salt & Pepper)')
ax[3].set_title('Noise Added Image (Poisson)')
for a in ax: