Image Processing Chapter 5

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 33

Image

12/07/21

Processing
Image Restoration

1
Contents
12/07/21

Image Restoration

Salt & pepper noise.

Gaussian noise.

Speckle noise.

Periodic noise.

Cleaning salt and pepper noise

Cleaning Gaussian noise

Cleaning Periodic noise

2
Image Restoration
12/07/21

Image restoration concerns the removal or


reduction of degradations which have occurred
during the acquisition of the image

Such degradations may include noise, which are


errors in the pixel values, or optical effects such as
out of focus blurring, or blurring due to camera
motion.

3
Image Restoration cont.

 Assume we have an image of f(x,y) and a spatial


filter h(x,y) if h(x,y) consists of a single line of ones,
the result of the convolution will be a motion blur in
the direction of the line. Thus we may write

g(x,y) =f(x,y)*h(x,Y)
 We may use additive function to generate noise

g(x,y) =f(x,y)*h(x,y)+n(x,y)
 If we know h,n we may acquire the original image

f(x,y)= (g(x,y)-n(x,y))/h(x,y)
Noise

We may define noise to be any degradation in the


image signal, caused by external disturbance. If an
image is being sent electronically from one place to
another, via satellite or wireless transmission, or
through networked cable, we may expect errors to
occur in the image signal

 Cleaning an image corrupted by noise is thus an


important area of image restoration.
Salt and Pepper noise

Its appearance is randomly scattered white or

black pixles over the image


tw=imread('twins.tif');

t=rgb2gray(tw);
 To add noise, we use the Matlab function imnoise which takes a

number of different parameters.

 To add salt and pepper noise

t_sp=imnoise(t,'salt & pepper'); or

imnoise(t,'salt & pepper',0.2);


 would produce an image with 20% of its pixels corrupted by salt
and pepper noise
Salt and Pepper noise-Cont

Original image With added salt &


pepper noise
Gaussian noise-Cont.

 Gaussian noise is an idealized form of white noise .


We can observe white noise by watching a television
which is slightly mistuned to a particular channel.

 If the image is represented as I. and the Gaussian


noise by
N , then we can model a noisy image by simply adding
the two: I+N
t_spk=imnoise(t, ‘Gaussian ');
Speckle noise

Whereas Gaussian noise can be modeled by random


values added to an image . speckle noise can be
modeled by random values multiplied by pixel values
hence it is also called multiplicative noise.

t_spk=imnoise(t,'speckle');

peckle noise is implemented as

I(1+N)
Speckle noise-Cont.

Gaussian noise Speckle noise


Periodic noise

The function imnoise does not have a periodic option,


but it is quite easy to create our own, by adding a
periodic matrix

>> s=size(t);

>> [x,y]=meshgrid(1:s(1),1:s(2));

>> p=sin(x/3+y/5)+1;

>> t_pn=(im2double(t)+p/2)/2;
Periodic noise-Cont.

Periodic noise
Cleaning salt and pepper noise

 Low pass filter


 So we might try filtering with an average filter:
 a3=fspecial('average');
 t_sp_a3=filter2(a3,t_sp);
Median filtering

 Median filtering seems almost tailor-made for


removal of salt and pepper noise.
 The median of a set is the middle value when they
are sorted
 Thus the median will in general replace a noisy value
with one closer to its surroundings

A median filter is an example of a non-linear


spatial filter
Median filtering-Cont.

In Matlab, median filtering is implemented by the


medfilt2 function
t_sp_m3=medfilt2(t_sp) ;

Median filtering
Rank-order filtering

 Median filtering is a special case of a more general


process called rank-order filtering Rather than take
the median of a set, we order the set and take the
n_th th value, for some predetermined value of n
ordfilt2(t_sp,3,[0 1 0;1 1 1;0 1 0]);
Rank-order filtering-Cont.

 Applying the median filter can in general be a slow


operation: each pixel requires the sorting of at least
nine values .The use of cleaning salt and
 pepper noise by treating noisy pixels known as
outliers.

 This leads to the following approach for noise


cleaning.
1. Choose a threshold value D
2. For a given pixel, compare its value P with the mean
M of the values of its eight neighbors
3. If(P-M)>D then classify the pixel as noisy,
otherwise not
4. If the pixel is noisy, replace its value with M
otherwise leave its value unchanged.
Rank-order filtering-Cont.
Rank-order filtering-Cont.

D=.2 D=.4
Cleaning Gaussian noise

It may sometimes happen that instead of just one


image corrupted with Gaussian noise, we have many
different copies of it. An example is satellite imaging; if
a satellite passes over the same spot many times, we
will obtain many different images of the same place
Simple approach to cleaning Gaussian noise is to
simply take the average of all the images .
To see why this works, suppose we have 100 copies of
our image, each with noise then the Ith noisy image
will be:M+NI
M is the matrix of original values and NI a matrix of
normally distributed random values with mean 0
We can define the mean M´ of these images by the
usual add and divide method
Cleaning Gaussian noise-Cont.
Removal of periodic noise

 Periodic noise may occur if the


imaging equipment is subject to
electronic disturbance of a repeating
nature.

 We can easily create periodic noise by


overlaying an image with a
trigonometric function:
Removal of periodic noise-Cont

>> [x,y]=meshgrid(1:256,1:256);
>> p=1+sin(x+y/1.5);
>> cm = imread('cameraman.tif');
>> tp=(double(cm)/128+p)/4;
>> imshow(tp)
>>fcm = fftshift(fft(tp));
>>figure,imshow(fcm)

Where cm is cameraman image.


Removal of periodic noise-Cont

 The second line simply creates a sine function,


and adjusts its output to be in the range 0-2.

 The third line first adjusts the cameraman


image to be in the same range; adds the sine
function to it, and divides by 4 to produce a
matrix of type double with all elements in the
range 0.0 – 1.0.
Removal of periodic noise-Cont
This can be viewed directly with imshow,
and it is shown in gure 6.1(a). We can
produce its shifted DFT and this is shown
in gure 6.1(b). The extra two spikes
away from the centre correspond to the
noise just added.

The extra two spikes away from the centre


correspond to the noise just added.
Removal of periodic noise-Cont
Removal of periodic noise-Cont

There are two methods we can use to


eliminate the spikes :

1. Band reject filtering.

2. Notch filtering.
Removal of periodic noise-Cont

 Band reject filtering


We create a filter consisting of ones with a ring
of zeroes; the zeroes lying at a radius of 49
from the centre:
>> z=sqrt((x-129).^2+(y-129).^2);
>> br=(z < 47 | z > 51);

where z is the matrix consisting of distances


from the origin. This particular ring will have a
thickness large enough to cover the spikes. Then
as before, we multiply this by the transform:
>> tbr=fcm.*br;
>> figure,imshow(tbr,[])
Removal of periodic noise-Cont

 and this is shown in figure 6.2(a).


 The result is that the spikes have
been blocked out by this filter.
 Taking the inverse transform
produces the image shown in gure
6.2(b).
 Note that not all the noise has gone,
but a significant amount has,
especially in the centre of the image.
Removal of periodic noise-Cont
Removal of periodic noise-Cont

Notch filtering
With a notch Filter, we simply make
the rows and columns of the spikes
zero:
>> tf(156,:)=0;
>> tf(102,:)=0;
>> tf(:,170)=0;
>> tf(:,88)=0;
and the result is shown in gure 6.3(a).
The image after inversion is shown in
gure 6.3(b).
Removal of periodic noise-Cont
Any questions

LOGO

You might also like