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 skimage.io
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 = skimage.io.imread(fname='candy.jpg')
#Displaying the image
skimage.io.imshow(candy)
plt.title('Original Image')
plt.axis('off')
(-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)
skimage.io.imshow(gauss_blurred)
plt.title('Gaussian Filter Applied Image')
plt.axis('off')
(-0.5, 899.5, 719.5, -0.5)
We observe that the sharpness of the image is reduced and colors blend in more.
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 = skimage.io.imread('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].imshow(land)
ax[0].set_title('Original Image')
ax[1].imshow(g_noised_image)
ax[1].set_title('Noise Added Image (Gaussian)')
ax[2].imshow(sp_noised_image)
ax[2].set_title('Noise Added Image (Salt & Pepper)')
ax[3].imshow(poisson_noised_image)
ax[3].set_title('Noise Added Image (Poisson)')
fig.tight_layout()
for a in ax:
a.axis('off')