You are on page 1of 9

A COMPARATIVE STUDY OF VARIOUS NOISE

FILTERING TECHNIQUES IN DIGITAL IMAGES


Ashutosh Agrawal
3rd year, Integrated M.Sc. Applied mathematics
17312007
Supervisor: Dr. Rama Bhargava
1. Abstract
Most of the images we receive contain some distortions from the real image; these distortions are usually referred to as
noise. It may arise from a variety of sources such as detector sensitivity variations, transmission, etc. The digital image
processing system contains operators to add some noises artificially. Corrupting an image with noise deliberately to get a
distorted image and then using known filters to test their effectiveness for each type of noise is the main aim of this
report.
2. Introduction
Noise is an unknown variation of image Intensity. The pixels have different intensity values instead of the real pixel
values.
The filters reduce or remove the visibility of noise by smoothing the image except the areas near contrast boundaries.
Different noises have their peculiar characteristics. And those features make them distinguishable from each other.
Noise can enter an image due to image acquisition, transmission, reproduction, etc.
To recover the original picture from the corrupted image, noise removal algorithms are used. Denoising means the
removal of unwanted noises from a digital image.

g(x, y)= f (x, y) +η (x, y)


Where f(x, y) = original pixel, g(x, y) = noisy pixel, η(x, y) = noise term,

Original Image

3. TYPES OF NOISE
Different noise will affect the image to an entirely different extent. In the report, only the most common noises will be
taken into consideration.
• Gaussian Noise
• Poisson Noise
• Salt & pepper Noise (Impulse Noise)
• Speckle Noise

Above listed are not all the noises, but these noises are the most common ones.
3.1 Gaussian Noise
Gaussian noise is a noise having a pdf that of the Normal distribution. It is a type of additive noise as each pixel is
changed such that a specific distribution is added to every pixel. The most commonly seen is the Gaussian distribution. It
is caused because of inefficient lighting while capturing the picture or high temperatures. The pdf is given by the formula

Corrupting the original


image with gaussian noise
with mean = 0 & var = 0.003.

3.2 Poisson Noise


Poisson noise follows a Poisson distribution, which is not very different from Normal. The photon noise and many
unusual sensor-based device noises corrupt the signals in varying proportions. It is also called as shot noise or sometimes
photon noise as well.
The distribution function of Poisson Noise is given below;

Corrupting the original


image with Poisson noise
3.3 Salt and pepper Noise (Impulse Noise)
The corrupted pixels are either set to the maximum value or the least value. In some cases, individual pixels are set
alternatively to zero or the maximum value; the noise affects only a small no. of pixels. In salt and pepper noise, the noisy
pixels take either pepper value (lowest value, i.e., 0) or salt value (highest value, i.e., 225). It is caused because of
instantaneous disturbances or errors in data transmission. It appears as black and white spots on the images.

Corrupting the original image


with salt and pepper noise

3.4 Speckle Noise


Speckle noise is a noise in which random values are multiplied by pixel values of an image. Speckle noise is multiplicative
noise, unlike the Gaussian and Salt and Pepper type noise. It makes any random distribution to be multiplied to each
pixel in the picture. Ultrasounds, sonar, and laser are usually affected by this noise. This noise also increases the mean
intensity level of the image. This noise creates a significant amount of problems in retracting the image.
J = I + n*I
Where J is the speckle noise distribution image, I is the input image, and n is the uniform noise image by mean
0 and variance v.

Corrupting the original image with speckle noise


4. Experimental Results
4.1 Denoising Techniques
a) Mean filter
Mean filtering is easy to implement-method of smoothing images (reducing the amount of intensity difference between
the neighboring pixels). The idea of mean filtering is simply to replace each pixel value in a picture with the mean value of
its neighbors, including itself. The mean filter has the effect of eliminating pixel values that are unrepresentative of their
surroundings. The main problem with the mean filter is, a particular pixel with a very distinct value can affect the mean
value of all the neighboring pixels quite significantly. Also, If the filter neighborhood has an edge, the filter will add new
values for pixels and will smoothen that edge. This will be a problem if sharp edges are required in the output.

Arithmetic mean filter


1
𝑓𝑓̂(𝑥𝑥, 𝑦𝑦) = ∑(𝑠𝑠,𝑡𝑡)∈𝑆𝑆 𝑔𝑔(𝑠𝑠, 𝑡𝑡).
𝑥𝑥𝑥𝑥
𝑚𝑚𝑚𝑚

b) Wiener filter
The Wiener filter is an adaptive kind of filter for processing signals. When the variance is small, wiener performs better
blurring, and when the variance is high, Weiner shows little blurring. The Wiener filter is typically more selective than the
average filter as it retains edges and high-frequency elements of a picture as well.
Wiener Filter in the Fourier Domain;

c) Median filter
The median filter is a non-linear filter that replaces the intensity level by the median of the intensity values of pixels in a
neighborhood. The Median filter is famous for denoising without smoothing edges of the image. Its edge saving nature
makes it quite useful. This filter reduces the intensity variation between pixels of an image. In this filter, the pixel value of
the image is replaced with the median value. Intensities of the neighboring pixels are arranged in the ascending order,
and the =n median is calculated by picking up the middle element.
𝑓𝑓^(𝑥𝑥,𝑦𝑦) = 𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚{𝑔𝑔(𝑠𝑠,𝑡𝑡)} 𝑤𝑤ℎ𝑒𝑒𝑒𝑒𝑒𝑒 (𝑠𝑠,𝑡𝑡) ∈ 𝑆𝑆𝑆𝑆𝑆𝑆

5. Performance Parameters:
a) Mean Square Error (MSE)
The MSE is the cumulative square error between the processed image and the original image. It is defined by:

Where f is the original image, and g is the processed image. The dimension of the image is m X n. Thus, MSE should be as
low as possible for higher effectiveness.
b) Peak Signal to Noise ratio or PSNR
PSNR is the ratio between the maximum possible intensity of a signal and the power of distorting noise, which affects the
quality of its representation. The following formula defines it:
6. Results
PSNR and MSE value for gaussian noise
Filtering Technique PSNR MSE
Distorted img 23.51966448 0.00444665
Mean 26.96109534 0.00201321
Median 27.39441356 0.00182204
Wiener 24.10291577 0.00388784

PSNR and MSE value for Poisson noise


Filtering Technique PSNR MSE
Distorted img 18.68620219 0.01353255
Mean 25.13491771 0.00306551
Median 25.15106721 0.00305417
Wiener 23.7439281 0.00422286

PSNR and MSE value for S&P noise


Filtering Technique PSNR MSE
Distorted img 27.80768988 0.00165665
Mean 27.14953299 0.00192773
Median 28.61501742 0.00137561
Wiener 24.25397581 0.00375493

PSNR and MSE value for speckle noise


Filtering Technique PSNR MSE
Distorted img 21.39634113 0.00725046
Mean 25.82428068 0.0026156
Median 25.95258995 0.00253945
Wiener 24.04748367 0.00393778

PROCESSED IMAGES AND PYTHON CODE FOR THE SAME ARE AT THE END OF THE REPORT.

7. Conclusion
Denoising of a noisy digital image is a critical task in image processing. So, a known artificial noise is added to the picture
just to understand the algorithms of denoising and their effectiveness. In this report, we have discussed different types
of noises in images during image acquisition or transmission arising due to various limitations. We have also discussed
the causes of the common noises and their primary sources. We have also discussed different commonly used filtering
methods that can be used to filter the images. Major conclusions;
• After observing the PSNR and MSE values, We can say that the median filter works better in denoising the
image in all the noise models.
• We also find that the Median filter filters noticeably well for S&P noise and Gaussian noise.
• Since the Wiener Filter preserves edges from different angles, hence, it can be used for restoring the blurred
image.

APPLYING DIFFERENT FILTERS ON GAUSSIAN NOISE

NOISY IMAGE MEAN FILTER

MEDIAN FILTER WIENER FILTER

APPLYING DIFFERENT FILTERS ON POISSON NOISE

NOISY IMAGE MEAN FILTER

MEDIAN FILTER WIENER FILTER


APPLYING DIFFERENT FILTERS ON SALT & PEPPER NOISE

NOISY IMAGE MEAN FILTER

MEDIAN FILTER WIENER FILTER

APPLYING DIFFERENT FILTERS ON SPECKLE NOISE

NOISY IMAGE MEAN FILTER

MEDIAN FILTER WIENER FILTER


PYTHON CODE FOR OBTAINING ABOVE IMAGES
#!/usr/bin/env python
# coding: utf-8

import numpy as np
from skimage import filters
from skimage import restoration
import matplotlib.pyplot as plt
import cv2
import random

from skimage.measure import compare_ssim as ssim


from skimage.measure import compare_psnr as psnr

def rgb2gray(rgb):
return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])

def mse(img, noisy):


n,m = img.shape;
ans = 0
for i in range(0,n):
for j in range(0, m):
ans = ans + (img[i,j] - noisy[i,j])*(img[i,j] - noisy[i,j])
return ans/(n*m)

def noisy(noise_typ,image):
if noise_typ == "gauss":
row,col= image.shape
mean = 0
var = 0.003
sigma = var**0.5
gauss = np.random.normal(mean,sigma,(row,col))
gauss = gauss.reshape(row,col)
noisy = image + gauss
return noisy
elif noise_typ == "s&p":
row,col = image.shape
s_vs_p = 0.5
amount = 0.006
out = np.copy(image)
# Salt mode
num_salt = np.ceil(amount * image.size * s_vs_p)
coords = [np.random.randint(0, i - 1, int(num_salt))
for i in image.shape]
out[coords] = 1

# Pepper mode
num_pepper = np.ceil(amount* image.size * (1. - s_vs_p))
coords = [np.random.randint(0, i - 1, int(num_pepper))
for i in image.shape]
out[coords] = 0
return out
elif noise_typ == "poisson":
vals = len(np.unique(image))
vals = 1.5**np.ceil(np.log2(vals))
noisy = np.random.poisson(image * vals) / float(vals)
return noisy
elif noise_typ =="speckle":
row,col = image.shape
gauss = 0.1*np.random.randn(row,col)
gauss = gauss.reshape(row,col)
noisy = image + image * gauss
return noisy

def construct(img, noisy):


#psf = np.ones((2, 2)) / 4
#denoised = restoration.wiener(noisy, psf, 1)

selem=np.ones((3,3))
#denoised = filters.median(noisy, selem)
denoised = filters.rank.mean(noisy, selem)

denoised = (denoised - denoised.min())/(denoised.max() - denoised.min())


txt1 = "psnr : " + str(psnr(img, noisy, data_range=img.max() - img.min())) +
"\nmse : " + str(mse(img, noisy))
txt2 = "psnr : " + str(psnr(img, denoised, data_range=denoised.max() -
denoised.min())) + "\nmse : " + str(mse(img, denoised))

f, ax = plt.subplots(1,3, figsize = (20,20))


[axi.set_axis_off() for axi in ax.ravel()]
ax[0].set_title('original')
ax[0].imshow(img, cmap = 'gray')
ax[1].text(0.95, 0.01, txt1, verticalalignment='bottom', fontsize = 15)
ax[1].imshow(noisy, cmap = 'gray')
ax[2].text(0.95, 0.01, txt2, verticalalignment='bottom', fontsize = 15)
ax[2].imshow(denoised, cmap = 'gray')

plt.show()

#Input image is 'img', and generated noisy image is 'noisy'


np.random.seed(1)
img = cv2.imread('./lena.png')
img = rgb2gray(img)
img = (img - img.min())/(img.max() - img.min())
noisy = noisy("poisson", img)
noisy = (noisy - noisy.min())/(noisy.max() - noisy.min())
construct(img, noisy)

REFERENCES
• Digital Image Processing 4th Edition by Rafael C. Gonzalez Richard E. Woods

• S. Jayaraman, “Digital Image Processing”, Tata McGraw Hill Education,

• https://www.tutorialspoint.com/image-processing-in-python

• William K. Pratt, Digital Image Processing. Wiley

• Dr. Philippe Cattin (2012-04-24). "Image Restoration: Introduction to Signal and Image
Processing". MIAC, University of Basel.

• https://stackabuse.com/introduction-to-image-processing-in-python-with-opencv/

You might also like