Professional Documents
Culture Documents
Origin of Noise
Noise in a digital image arises mainly due
to acquisition (digitization) and / or
transmission.
Environmental conditions, quality of
sensing elements, interference in the
transmission channel, lightning and
atmospheric disturbance are some
examples.
Properties of Noise
When the Fourier spectrum of noise is constant,
the noise is called a white noise.
This is similar to white light, which contains
nearly all frequencies in the visible spectrum in
equal quantities.
Fourier spectrum of a function containing all
frequencies in equal proportions is a constant.
We assume that noise is independent of
coordinates, and it is uncorrelated with respect
to the pixel values.
Noisy Image
% Gaussian noise
% Read a gray scale image (having few regulat
patterns) and add gaussian
% noise of certain mean value,standard deviation and
certain percentage.
% plot the histogram of noise, noisy image. ensure that
the profile of the
% noise is visible in the profile of the noisy image.
clear all; close all; clc;
a = imread('pattern.png');
a = im2double(a);
sizeA = size(a);
p3 = 0; % Gaussian noise mean value
p4 = 1; % Gaussian noise variance value
R = p3+p4*randn([256,256]);
R1 = a+R;
figure,imshow(R1),title('Noisy Image');
figure,hist(R,50),title('Probability density function');
Rayleigh noise
The PDF of Rayleigh noise is given by
p(z) = (2/b)*(z-a)*exp(-(z-a)2/b for z a
= 0
for z < a
The mean and variance of this PDF are:
= a + sqrt(b/4) and 2 = b(r )/4.
One has to note the displacement of PDF
from the origin and skewed to the right.
Thus this is useful for skewed histograms.
Noisy Image
% Rayleigh noise
% Read a gray scale image (having few regulat patterns) and add rayleigh
% noise of certain mean value,standard deviation and certain percentage.
% plot the histogram of noise, noisy image. ensure that the profile of the
% noise is visible in the profile of the noisy image.
clear all; close all; clc;
a = imread('pattern.png');
a = im2double(a);
sizeA = size(a);
p3 = 0.95;
A = 0; B = 2;
R = A + (-B*log(1-rand(sizeA))).^0.5;
x = rand(sizeA);
b=a;
for i=1:sizeA(1)
for j=1:sizeA(2)
if (x(i,j)< p3)
b(i,j)=a(i,j)+R(i,j);
end
end
end
figure,imshow(a);
figure,imshow(b),title('Noisy Image');
figure,hist(R,50),title('Probability density function');
figure,hist(b);
abzb-1
(b -1) !
=
0
for z < 0
Here a > 0, b is a positive integer. The
mean and variance of this density are:
Noisy Image
Exponential noise
The PDF of exponential noise is given as:
= 0 for z < 0
Here a > 0. The mean and variance of
this density function are
= (1/a) and 2 = (1/a2).
This PDF is the special case of the Erlang
PDF, with b =1.
Noisy Image
% Exponential noise
% Read a gray scale image (having few regulat patterns) and add exponential
% noise of certain mean value,standard deviation and certain percentage.
% plot the histogram of noise, noisy image. ensure that the profile of the
% noise is visible in the profile of the noisy image.
clear all; close all; clc;
a = imread('pattern.png');
a = im2double(a);
sizeA = size(a);
p3 = 0.9;
A = 1;
k = -1/A;
R = k*log(1-rand(sizeA));
x = rand(sizeA);
b=a;
for i=1:sizeA(1)
for j=1:sizeA(2)
if (x(i,j)< p3)
b(i,j)=a(i,j)+R(i,j);
end
end
end
figure,imshow(a);
figure,imshow(b),title('Noisy Image');
figure,hist(R,50),title('Probability density function');
figure,hist(b);
Uniform noise
The PDF of uniform noise is given by:
p(z) = (1/(b-a)) if a z b
= 0
otherwise
The mean and variance are given as:
= (a+b)/2 and 2 = ((b-a)2)/12.
Noisy Image
% Uniform noise
% Read a gray scale image (having few regulat patterns) and add uniform
% noise of certain mean value,standard deviation and certain percentage.
% plot the histogram of noise, noisy image. ensure that the profile of the
% noise is visible in the profile of the noisy image.
clear all; close all; clc;
a = imread('pattern.png');
%a = zeros([256,256]);
a = im2double(a);
sizeA = size(a);
A = 0; % Min noise level
B = 1; % Max noise level
p3 = 0.95; % Noise percentage
R = A + (B - A)*rand(sizeA);
x = rand(sizeA);
b=a;
for i=1:sizeA(1)
for j=1:sizeA(2)
if x(i,j) < p3
b(i,j)=a(i,j)+R(i,j);
end
end
end
figure,imshow(a);
figure,imshow(b),title('Noisy Image');
figure,hist(R,50),title('Probability density function');
figure,hist(b);
p(z) = Pa for z = a
= Pb for z = b
= 0 otherwise
If b > a, gray-level b will appear as a light dot in
the image. Level a will appear like a dark dot.
If either Pa or Pb is zero, the impulse noise is
called unipolar.
If both the probabilities are equal, impulse noise
will resemble salt and pepper noise.
Hence bipolar noise is also called as salt-andpepper noise or Shot and spike noise.
Impulse Noise
Noise impulses can be positive or negative.
Generally impulse corruption is large compared
to the strength of image signal and hence are
treated as extreme (black or white) values.
Negative impulses appear s black (pepper)
points.
Positive impulses appear white (salt) noise.
For an 8 bit image a = 0 (black) and b = 255
(white).
Noisy Image
Origin of Noises
Gaussian noise arises in an image such as
electronic circuit noise and sensor noise due to
poor illumination and/or high temperature.
The Rayleigh noise arises in range imaging.
The exponential and gamma noises appear in
laser imaging.
Impulse noise is found in places where quick
transients, such as faulty switching take place
during imaging.
Gaussian Noise
Salt Noise
Pepper Noise
Noisy Image
Max filter
Noisy Image
Min filter
Midpoint filter
This filter is simply the midpoint between
the maximum and minimum values in the
area enclosed by the filter:
f(x,y) = (1/2) * [ max {g(s,t)} + min {g(s,t)}]
This filter combines order statistic and
averaging.
It is good for randomly distributed noise,
like Gaussian or uniform noise.
Noisy Image
Midpoint filtered
% Midpoint filter
% Read a gray scale image and add gaussian noise and remove the noise using
% midpoint filter
clear all; close all; clc;
f = imread('cameraman.tif');
f = imnoise(f,'gaussian',0,0.01);
f = im2double(f);
%subplot(1,2,1),imshow(f),title('Noisy Image');
figure,imshow(f),title('Noisy Image');
[m n]=size(f);
Q=0;
for i = 2:m-1
for j = 2:n-1
con=0;
for k1 = i-1:i+1
for p1 = j-1:j+1
con = con+1;
s1(con)=(f(k1,p1));
end
end
b1=min(s1); b2=max(s1);
R_img(i,j)=(b1+b2)/2;
end
end
%subplot(1,2,2),imshow(R_img),title('Midpoint filtered');
figure,imshow(R_img),title('Midpoint filtered');
Noisy Image
% trimed mean filter. prove that for D=0 it becomes arithmetic mean filter
% and for d=(mn-1)/2 it becomes median filter. show that this filter
% removes combination of gaussian and salt & pepper noise.
clear all; close all; clc;
f = imread('cameraman.tif');
f = im2double(f);
f = imnoise(f,'salt & pepper',0.1);
f = imnoise(f,'gaussian',0,0.01);
[m n]=size(f);
f1=zeros(m,n);
D = 4;
d = D/2;
for i=3:m-2
for j=3:n-2
con=0;
for k=i-2:i+2
for p=j-2:j+2
con=con+1;
s(con)=f(k,p);
end
end
s = sort(s);
r = (size(s,2)-d);
s1= s(d+1:r);
f1(i,j)= sum(s1)/(con-D);
end
end
figure,imshow(f),title('Noisy Image');
Adaptive filters
The filters discussed above, do not worry about the
image characteristics.
Adaptive filters are one whose behavior changes based
on statistical characteristics of the image inside the filter
region defined by the m X n subimage.
Adaptive, local noise reduction filter
Mean and variance are the simple statistical feature of a
random variable.
They are related to the appearance of an image.
Mean gives a measure of average gray level in the
region over which the mean is computed and variance
gives a measure of average contrast in that region.
Response of a filter
The response of a filter at (x,y) depends
on:
g(x,y), the value of the noisy image at (x,y).
2, the variance of the noise corrupting the
image f(x,y)
mL, the local mean of the pixels in Sxy.
L2, the local variance of the pixels in S xy.
Behavior of a filter
The filter should behave as follows:
If 2 is zero, filter should return the value of
g(x,y).
If local variance is high relative to 2, the filter
should return a value close to g(x,y).
A high local variance is related with edges, and
should be preserved.
If the 2 variances are equal, the filter should
return the arithmetic mean value of the pixels in
Sxy.
Behavior of a filter
An adaptive expression for obtaining f(x,y)
based on these assumptions is given as:
Behavior of a filter
Here if the estimate of 2 is too low, then the
algorithm will return an image that resembles the
original image as the correction factors are too
small.
If the estimates are too high, the ratio of the
variances need to be clipped at 1.0 and the
algorithm will subtract the man from the image
more frequently than it would normally do so.
If negative values are permitted, the image is
rescaled at the end and the result is a loss of
dynamic range.
% Read a gray scale image and add gaussian noise with 0 mean then apply
% the Adaptive local noise reduction filter.
clear all; close all; clc;
f = imread('cameraman.tif');
f = im2double(f);
[m n]=size(f);
f1=zeros(m,n);
f = imnoise(f,'gaussian',0,0.1);
D = std2(f);
M = mean2(f);
for i=3:m-2
for j=3:n-2
con=0; s=0; s1=0;
for k=i-2:i+2
for p=j-2:j+2
con=con+1;
s = s+f(k,p);
s1(con)=f(k,p);
end
end
lm=s/con;
ld = std(s1);
if ld >0
f1(i,j) = f(i,j)-((D*(f(i,j)-lm)/ld));
else
f1(i,j) = f(i,j)-0;
end
end
end
figure,imshow(f),title('Gaussian Noise Image');
figure,imshow(f1),title('Adaptive Local Noise Filtered');
A2 = zmed zmax
B2 = zxy zmax
Else output z .
Noise Image
After filtering