DEPARTMENT:
ELECTRONICS ENGINEERING
SUBJECT:
DIGITAL IMAGE PROCESSING
STUDENT NAME:
MWIGHUSA (唐德宁)
SUPERVISOR:
DR. DING XUEWEN (丁学文)  PhD
PROJECT TITLE:
IMAGE RESTORATION
DATE: 24TH NOVEMBER
1Page
Overview:
In the past two decades, the technique of image processing has made its way into every aspect of
today’s techsavvy society. Its applications encompass a wide variety of specialized disciplines
including medical imaging, machine vision, remote sensing and astronomy. Personal images
captured by various digital cameras can easily be manipulated by a variety of dedicated image
processing algorithms. Image restoration can be described as an important part of image processing
technique. The basic objective is to enhance the quality of an image by removing defects and make
it look pleasing. The method used to carry out the project was MATLAB software. Mathematical
algorithms were programmed and tested for the result to find the necessary output. In this project
mathematical analysis was the basic core. Generally the spatial and frequency domain methods
were both important and applicable in different technologies. This project has tried to show the
comparison between spatial and frequency domain approaches and their advantages and
disadvantages. This project also suggested that more research have to be done in many other image
processing applications to show the importance of those methods.
Acknowledgements:
The author remains thankful to Dr. Ding Xuewen (Dr. & Lecturer, Dept. of Electronics &
Electrical Engineering, Tianjin University of Technology & Education, Tianjin, China P.R) for his
useful discussions and suggestions during the preparations of this project.
2Page
Contents
Introduction………………………………………………………………………………………..1
Image Noise Model………………………………………………………………………………..2
Noise Types……………………………………………………………………………….3
Filters……………………………………………………………………………………………...6
Filtering Techniques………………………………………………………………………7
Noise Filtering in Spatial and Frequency Domain………………………………………………...8
Filtering to remove noise………………………………………………………………….8
Order statistic filters……………………………………………………………………...11
Adaptive Filters…………………………………………………………………………………..15
Adaptive Filters Example………………………………………………………………..17
Periodic Noise……………………………………………………………………………………17
Band Reject Filters……………………………………………………………………………….17
Band Reject Filters Example…………………………………………………………….18
Advantage and Disadvantage of Spatial and Frequency Domain Methods……………………...19
Conclusion……………………………………………………………………………………….19
Reference………………………………………………………………………………………...20
3Page
IMAGE RESTORATION
Introduction
Image Restoration is the process of obtaining the original image from the degraded image given
the knowledge of the degrading factors. Digital image restoration is a field of engineering that
studies methods used to recover original scene from the degraded images and observations.
Techniques used for image restoration are oriented towards modeling the degradations, usually
blur and noise and applying various filters to obtain an approximation of the original scene. There
are a variety of reasons that could cause degradation of an image and image restoration is one of
the key fields in today's Digital Image Processing due to its wide area of applications. Commonly
occurring degradations include blurring, motion and noise. Blurring can be caused when object in
the image is outside the camera’s depth of field sometime during the exposure, whereas motion
blur can be caused when an object moves relative to the camera during an exposure.
Fig. Image Restoration example
The purpose of image restoration is to "compensate for" or "undo" defects which degrade an image.
Degradation comes in many forms such as motion blur, noise, and camera misfocus. In cases like
motion blur, it is possible to come up with a very good estimate of the actual blurring function and
"undo" the blur to restore the original image. In cases where the image is corrupted by noise, the
best we may hope to do is to compensate for the degradation it caused. In this project, we will
introduce and implement several of the methods used in the image processing world to restore
images. The field of image restoration (sometimes referred to as image deblurring or image deconvolution) is concerned with the reconstruction or estimation of the uncorrupted image from a
blurred and noisy one. Essentially, it tries to perform an operation on the image that is the inverse
of the imperfections in the image formation system. In the use of image restoration methods, the
characteristics of the degrading system and the noise are assumed to be known a priori. In practical
situations, however, one may not be able to obtain this information directly from the image
formation process. The goal of blur identification is to estimate the attributes of the imperfect
imaging system from the observed degraded image itself prior to the restoration process. The
combination of image restoration and blur identification is often referred to as blind image deconvolution. Image restoration algorithms distinguish themselves from image enhancement
methods in that they are based on models for the degrading process and for the ideal image. For
4Page
those cases where a fairly accurate blur model is available, powerful restoration algorithms can be
arrived at. Unfortunately, in numerous practical cases of interest, the modeling of the blur is
unfeasible, rendering restoration impossible. The limited validity of blur models is often a factor
of disappointment, but one should realize that if none of the blur models described in this chapter
are applicable, the corrupted image may well be beyond restoration. Therefore, no matter how
powerful blur identification and restoration algorithms are, the objective when capturing an image
undeniably is to avoid the need for restoring the image.
In restoration process, degradation is taken to be a linear spatially invariant operator –
Figure. Processing of Image Restoration 𝑔
(𝑥, 𝑦) = ℎ(𝑥, 𝑦) ∗ 𝑓(𝑥, 𝑦) + 𝜂(𝑥, 𝑦)
where, if g(x, y) is noise free, restoration can be done by using the inverse transfer function of h(u,
v) as the restoration filter and η(x, y) is the noise. The restoration techniques use various types of
filters for achieving best performance, like inverse filter, wiener filter, constrained least square
filter, Histogram Adaptive Fuzzy filter, Minmax Detector Based filter and Centre Weighted Mean
filter etc.
Image Noise Model
The sources of noise in digital images arise during image acquisition (digitization) and
transmission.
• Imaging sensors can be affected by ambient conditions
• Interference can be added to an image during transmission
We can consider a noisy image to be modelled as follows:
𝑔
(𝑥, 𝑦) = ℎ(𝑥, 𝑦) ∗ 𝑓(𝑥, 𝑦) + 𝜂(𝑥, 𝑦)
where f(x, y) is the original image pixel, η(x, y) is the noise term and g(x, y) is the resulting noisy
pixel. If we can estimate the model of the noise in an image, it will help us to figure out how to
restore the image.
5Page
Noise Types
For an image to be restored it is important to know the features of the noises that caused its
degradation. They have different features but the most important in this project are the spatial and
frequency properties.
Spatial properties mean dealing with the statistical behaviors of the noise component, while in
frequency properties deal with the frequency contents of the noise in Fourier form. There are
many noise patterns in image processing and some of them include:
a) Gaussian noise – is a noise type initiated by a Gaussian amplitude distribution. The Gaussian
probability distribution has a a probability density function of
2
2
1
𝑃
(𝑥) = 𝜎√2𝜋 𝑒 −(𝑥−𝜇) ⁄2𝜎
where 𝑥 is the gray level 𝜇 is the mean, 𝜎 is the standard deviation and 𝜎 2 is the variance.
b) Erlang (Gamma) noise – is a noise having a probability distribution function of
𝑃
(𝑧) = {
𝑎𝑏
𝑧 𝑏−1 −𝑎𝑧 𝑒
(𝑏−1)!
0
where the mean is a 𝜇 =
and “ ! ” is factorial.
𝑏
𝑎
𝑓𝑜𝑟
𝑧 ≥ 0
𝑓𝑜𝑟
𝑧 < 0
𝑏
and variance 𝜎 2 = 𝑎2 . The parameters a and b are positive integers
c) Exponential noise – is a noise with exponential probability density function of
𝑎𝑒
−𝑎𝑧 𝑓𝑜𝑟 𝑧 ≥ 0
𝑃
(𝑧) = {
0
𝑓𝑜𝑟
𝑧 < 0
where the mean 𝜇 =
1 𝑎
1
and 𝜎 2 = 𝑎2 for a > 0.
d) Uniform noise – is the noise with the probability density function of
1
𝑖𝑓
𝑎 ≤ 𝑧 ≤ 𝑏
𝑃
(𝑧) = {𝑏−𝑎
0
𝑜𝑡
ℎ𝑒𝑟𝑤𝑖𝑠𝑒
(𝑏−𝑎)2
𝑎
+𝑏
2
where the mean 𝜇 = 2 is and σ = 12 is variance.
e) Impulse noise(Saltandpepper) – is a noise type with a probability density function of
𝑃𝑎
𝑓𝑜𝑟
𝑧 = 𝑎
𝑃
(𝑧) = { 𝑃𝑏
𝑓𝑜𝑟
𝑧 = 𝑏
0
𝑜𝑡
ℎ𝑒𝑟𝑤𝑖𝑠𝑒
6Page
Noise Example
The test pattern to the right is ideal for demonstrating the addition of noise, The following
images will show the result of adding noise based on various models to the original image.
7Page
Original Image
8Page
Histogram
Filters
Elimination of noise is one of the major works to be done in computer vision and image processing,
as noise leads to the error in the image. Presence of noise is manifested by undesirable information,
which is not at all related to the image under study, but in turn disturbs the information present in
the image. It is translated into values, which are getting added or subtracted to the true gray level
values on a gray level pixel. These unwanted noise information can be introduced because of so
many reasons like: acquisition process due to cameras quality and restoration, acquisition
condition, such as illumination level, calibration and positioning or it can be a function of the scene
environment. Noise elimination is a main concern in computer vision and image processing. A
digital filter is used to remove noise from the degraded image. As any noise in the image can be
result in serious errors. Noise is an unwanted signal, which is manifested by undesirable
information. Thus the image, which gets contaminated by the noise, is the degraded image and
using different filters can filter this noise. Thus filter is an important subsystem of any signal
processing system. Thus filters are used for image enhancement, as it removes undesirable signal
components from the signal of interest. Filters are of different type i.e. linear filters or nonlinear
filters. In early times, as the signals handled were analog, filters used are of analog. Gradually
digital filters were took over the analog systems because of their flexibility, low cost,
programmability, reliability, etc. for these reasons digital filters are designed which works with
digital signals.
9Page
The designof digital filters involves three basic steps:
(i)
the specification of the desired properties of the system,
(ii)
the approximation of these specifications using a causal discrete time system, and
(iii) the realization of the system using finite precision arithmetic.
Filtering Techniques
Filtering is a technique for enhancing the image. Linear filter is the filtering in which the value of
an output pixel is a linear combination of neighborhood values, which can produce blur in the
image. Thus a variety of smoothing techniques have been developed that are non linear.
Median Filtering
Median filter (MF) is the one of the most popular nonlinear filter. Median filtering is one of the
spatial domain filter methods and as its name suggests that the median of the neighborhood pixel
value is taken and replaced with the neighborhood pixel values. The median of the pixels are taken
in such a way that the values are listed in the order from small value until big ones. Then the value
or values at the center of the list is or are taken as the median of the pixel values. In the case of
where two numbers becoming the median, it is important to take the average of the two values.
Median filtering is a very important and widely used technique of filtering and best known for its
excellent noise reduction ability. During filtering it keeps the edges while removing the noise. This
makes the image not to blur as other smoothening methods.
Spatial Filtering
In spatial filtering a certain filter mask is used in all points in an image. The filter mask is made of
m x n size where the m and n are the matrix sizes. In each case the image points should have the
same matrix size as of the filter mask with size M x N. There are two kinds of filtering, linear and
nonlinear spatial filtering. In lowpass filter the attenuation of high frequencies from frequency
domains causes in the blurring of an image. While in highpass filter the removal of low
frequencies cause in the sharpening of edges. Bandpass filtering is used for image restoration
while removing frequencies between high and low frequencies. There are many filters that are
used for blurring/smoothing, sharpening and edge detection in an image. These different effects
can be achieved by different coefficients in the mask.
Smoothing Spatial Filter
Smoothening filters can be obtained by averaging of pixels in the neighborhood of a filter mask.
It results in the blurring of an image. During noise removal or noise reduction sharp edges are
removed from the image. There are two kinds of filtering, linear and nonlinear spatial filtering. In
lowpass filter the attenuation of high frequencies from frequency domains causes in the blurring
of an image.
Inverse Filtering
If we know of or can create a good model of the blurring function that corrupted an image, the
quickest and easiest way to restore that is by inverse filtering. Unfortunately, since the inverse
filter is a form of high pass filer, inverse filtering responds very badly to any noise that is present
10  P a g e
in the image because noise tends to be high frequency. In this section, we explore two methods of
inverse filtering  a thresholding method and an iterative method.
Wiener Filtering
The inverse filtering is a restoration technique for deconvolution, i.e., when the image is blurred
by a known low pass filter, it is possible to recover the image by inverse filtering or generalized
inverse filtering. However, inverse filtering is very sensitive to additive noise. The approach of
reducing one degradation at a time allows us to develop a restoration algorithm for each type of
degradation and simply combine them. The Wiener filtering executes an optimal tradeoff between
inverse filtering and noise smoothing. It removes the additive noise and inverts the blurring
simultaneously. The Wiener filtering is optimal in terms of the mean square error. In other words,
it minimizes the overall mean square error in the process of inverse filtering and noise smoothing.
The Wiener filtering is a linear estimation of the original image. The approach is based on a
stochastic framework. The orthogonality principle implies that the Wiener filter in Fourier domain
can be expressed as follows:
where
are respectively power spectra of the original image and the additive
noise, and
is the blurring filter. It is easy to see that the Wiener filter has two separate part,
an inverse filtering part and a noise smoothing part. It not only performs the deconvolution by
inverse filtering (high pass filtering) but also removes the noise with a compression operation (low
pass filtering).
Noise Filtering in Spatial and Frequency Domain
Noise filtering techniques were discussed in the above sections. Here I discuss only new methods
for filtering in the spatial and frequency. A saltandpepper noise applied to the image has resulted
in an image in shown above. Using the median filtering technique caused the noise to be removed.
Analysis of Spatial and Frequency Methods and Results
In the above sections I tried to explain the methods used to filter noise for a digital image. Noise
filtering is carried out by spatial and frequency lowpass filtering, Contrast enhancement is carried
out with spatial domain histogram stretching and sharpening of an image uses the spatial and
frequency domain highpass filtering. The results of the methodologies will be discussed here.
Filtering to Remove Noise
We can use spatial filters of different kinds to remove different kinds of noise, The arithmetic
mean filter is a very simple one and is calculated as follows:
fˆ ( x, y )
11  P a g e
1
mn
g ( s, t )
( s ,t )S x y
This is implemented as the simple smoothing filter. Blurs the image to remove noise.
There are different kinds of mean filters all of which exhibit slightly different behaviour:
(i)
Geometric Mean
(ii)
Harmonic Mean
(iii) Contraharmonic Mean
There are other variants on the mean which can give different performance
Geometric Mean:
Achieves similar smoothing to the arithmetic mean, but tends to lose less image detail
ˆ
f ( x, y ) g ( s , t )
( s ,t )S x y
1
mn
Harmonic Mean:
The Harmonic Mean works well for salt noise, but fails for pepper noise, Also does well for
other kinds of noise such as Gaussian noise
ˆ ( x, y )
f
mn
( s ,t )S x y
12  P a g e
1
g ( s, t )
Contraharmonic Mean:
fˆ ( x, y )
g ( s, t ) Q 1
( s ,t )S x y
g ( s, t ) Q
( s ,t )S x y
Q is the order of the filter and adjusting its value changes the filter’s behaviour, Positive values
of Q eliminate pepper noise, Negative values of Q eliminate salt noise
Noise Removal Examples:
Original image
After a 3*3 arithmetic mean filter
13  P a g e
Image corrupted By Gaussian Noise
After a 3*3 geometric mean filter
Choosing the wrong value for Q when using the contraharmonic filter can have drastic results
Order Statistics Filters
Spatial filters that are based on ordering the pixel values that make up the neighbourhood operated
on by the filter, Useful spatial filters include:
(i) Median filter
(ii) Max and min filter
14  P a g e
(iii)Midpoint filter
(iv) Alpha trimmed mean filter
Median Filter:
Excellent at noise removal, without the smoothing effects that can occur with other smoothing
filters, Particularly good when salt and pepper noise is present
fˆ ( x, y ) median{g ( s, t )}
( s ,t )S x y
Max Filter:
fˆ ( x, y )
max { g ( s, t )}
( s ,t )S x y
Min Filter:
fˆ ( x, y )
min {g ( s, t )}
( s ,t )S x y
Max filter is good for pepper noise and min is good for salt noise
Midpoint Filter:
1
fˆ ( x, y )
max
{
g
(
s
,
t
)}
min
{
g
(
s
,
t
)}
( s ,t )S xy
2
( s ,t )S xy
Good for random Gaussian and uniform noise
AlphaTrimmed Mean Filter:
fˆ ( x, y )
1
mn d
g
( s ,t )S x y
r
( s, t )
We can delete the d/2 lowest and d/2 highest grey levels, So gr(s, t) represents the remaining mn
– d pixels
15  P a g e
Noise Removal Examples
Image
Corrupted
By Salt And
Pepper Noise
Result of 1
Pass With A
3*3 Median
Filter
Result of 2
Passes With
A 3*3 Median
Filter
Result of 3
Passes With
A 3*3 Median
Filter
16  P a g e
Image
Corrupted
By Pepper
Noise
Result Of
Filtering
Above
With A 3*3
Max Filter
17  P a g e
Image
Corrupted
By Salt
Noise
Result Of
Filtering
Above
With A 3*3
Min Filter
Image
Corrupted
By Uniform
Noise
Image
Further
Corrupted
By Salt and
Pepper
Noise
Filtered By
5*5
Arithmetic
Mean Filter
Filtered By
5*5
Geometric
Mean Filter
Filtered By
5*5 Median
Filter
Filtered By
5*5 AlphaTrimmed
Mean Filter
Adaptive Filters
The filters discussed so far are applied to an entire image without any regard for how image
characteristics vary from one point to another, The behaviour of adaptive filters changes
depending on the characteristics of the image inside the filter region, We will take a look at the
adaptive median filter
Adaptive Median Filtering
The median filter performs relatively well on impulse noise as long as the spatial density of the
impulse noise is not large, The adaptive median filter can handle much more spatially dense
impulse noise, and also performs some smoothing for nonimpulse noise, The key insight in the
adaptive median filter is that the filter size changes depending on the characteristics of the image
Remember that filtering looks at each original pixel image in turn and generates a new filtered
pixel.
18  P a g e
First examine the following notation:

zmin
zmax
zmed
zxy
Smax
= minimum grey level in Sxy
= maximum grey level in Sxy
= median of grey levels in Sxy
= grey level at coordinates (x, y)
=maximum allowed size of Sxy

Level A:

A2 = zmed – zmax

If A1 > 0 and A2 < 0, Go to level B

Else increase the window size

If window size ≤ Smax repeat level A

Else output zmed

Level B:

B2 = zxy – zmax

If B1 > 0 and B2 < 0, output zxy

Else output zmed
A1 = zmed – zmin
B1 = zxy – zmin
The key to understanding the algorithm is to remember that the adaptive median filter has three
purposes:
(i) Remove impulse noise
(ii) Provide smoothing of other noise
(iii)Reduce distortion
19  P a g e
Adaptive Filtering Example
Image corrupted by salt and
pepper noise with probabilities
P = P =0.25
a
Result of filtering with a 7 * 7
median filter
Result of adaptive median
filtering with i = 7
b
Periodic Noise
Typically arises due to electrical or electromagnetic interference, Gives rise to regular noise
patterns in an image, here Frequency domain techniques in the Fourier domain are most effective
at removing periodic noise
Band Reject Filters
Removing periodic noise form an image involves removing a particular range of frequencies from
that image, Band reject filters can be used for this purpose, An ideal band reject filter is given as
follows:
20  P a g e
1
H (u , v ) 0
1
if D (u , v ) D0
W
2
W
W
D (u , v ) D0
2
2
W
if D (u , v ) D0
2
if D0
The ideal band reject filter is shown below, along with Butterworth and Gaussian versions of the
filter
Ideal Band
Reject Filter
Butterworth
Band Reject
Filter (of order 1)
Gaussian
Band Reject
Filter
Band Reject Filter Example
Image corrupted by sinusoidal noise
Butterworth band reject filter
21  P a g e
Fourier spectrum of corrupted image
Filtered image
Table1. Advantages and Disadvantages of Spatial and Frequency domain methods
Advantages
Disadvantages
Spatial domain method
Frequency domain method
Direct manipulation of pixels
 Very good method for
contrast enhancement
 It is also a good method
for image sharpening
Sometimes it shifts image
boundaries during sharpening
Only manipulates the pixel
Manipulation of frequency
Best method for periodic
noise reduction
 Best method for image
sharpening
 Not a good method for
contrast enhancement
Only manipulates the
frequency
Table 1 suggested that both methods are important depending on the target needed. Spatial domain
method is advantageous in contrast enhancement, while frequency domain method in periodic
noise reduction and image sharpening.
Conclusion
Image restoration is an important field that is used in different scientific researches and technology
developments. In this paper different filtering techniques were discussed, we have also looked at
image restoration for noise removal, Restoration is slightly more objective than enhancement .
Spatial domain techniques are particularly useful for removing random noise, while Frequency
domain techniques are particularly useful for removing periodic noise. The differences among the
domains and their different methodologies were briefly explained. Generally the methods are both
important and applicable in different technologies. In this paper I tried to show a comparison
between both approaches and tried to show their advantages and disadvantages. This paper
suggests that more researches is needed on many other image processing applications to show the
importance of those methods.
22  P a g e
References
1. Digital Image Processing by R. C. Gonzales and R. E. Woods, AddisonWesley Publishing
Company, 1992.
2. TwoDimensional Signal and Image Processing by J. S. Lim, Prentice Hall, 1990.
3. 'Digital Image Restoration', by M.R. Banham and A.K. Katsaggelos, IEEE Signal Processing
Magazine, pp. 2741, March 1997.
http://www.sersc.org/journals/IJAST/vol39/5.pdf
http://www.jatit.org/volumes/researchpapers/Vol14No2/1Vol14No2.pdf
http://www.owlnet.rice.edu/~elec539/Projects99/BACH/proj2/refs.html
https://publications.theseus.fi/bitstream/handle/10024/29065/thesis_final7.pdf?sequence=1
KADIR, T., BRADY, M. 2001. Saliency, Scale and Image Description. International Journal
of Computer Vision, Volume 45, Number 2.
9. R. Plemmonsa, M. Horvatha, E. Leonhardta, P. Paucaa, S. Prasadb, “Computational Imaging
Systems
10. Class Presentation notes provided by Dr Xuewen Ding, Lecturer of Digital Image Processing,
Electrical and Electronics Engineering Dept, Tianjin University of Technology and
Education
4.
5.
6.
7.
8.
Appendices
Appendix 1
Spatial domain Algorithms
%contrast intensity manipulation using histogram equalization and certain %other %
load image1
whos %shows the size and parameters
figure(1)
imshow(X,map) %show the image1 image
I = ind2gray(X,map); %creating intensity of an image
figure(2)
imshow(I) %show intensity
A=I.^4; %high contrast created
A = 0.2*I; %low contrast created
figure(3)
subplot(2,1,1)
imshow(A) %show contrast image
subplot(2,1,2)
imhist(A)
grid
C=(A+.085)*3; %histogram stretching
figure(5)
subplot(2,1,1)
23  P a g e
imshow(C) %show histogram
subplot(2,1,2)
hist(A(:),50)
imhist(C)
grid 62
24  P a g e
%pixel manipulation with high pass filter mask%
load images
whos
figure(1)
imshow(X,map) % Indexed image
I=ind2gray(X,map); % Converting indexed image to intensity image
figure(2)
imshow(I) % Intensity image
%My=ones(3,3)/9; %averaging mask
My=zeros(3,3);
My(1,1)=1;
My(1,2)=1;
My(1,3)=1 ;
My(2,1)=1;
My(2,2)=8;
My(2,3)=1 ;
My(3,1)=1;
My(3,2)=1;
My(3,3)=1;
M=My; %the mask „My‟ can be changed depending on the result needed
FI=I; % Intiating the output matrix
for i=2:257
for j=2:349
FI(i,j)=sum(sum(I(i1:i+1,j1:j+1).*M)); %filtering with the mask
end
end
figure(4)
imshow(FI) 63
25  P a g e
% Implementing pixel group operation (mask operation, nearest %neighbour method,
filtering method)%
load images
figure(1)
imshow(X,map) % Indexed image
I=ind2gray(X,map); % Converting indexed image to intensity image
imshow(I) % Intensity image
SP=imnoise(I,'salt & pepper',0.4); % Corrupted image
figure(2)
imshow(SP)
%Median Filtering%
F2=SP;
for i=1+par:175 %258par
for j=1+par:225 %350par
AKE=SP(ipar:i+par,jpar:j+par); %ordering of pixels
F2(i,j)=median(AKE(:));
end
end
figure(4)
imshow(F2) 64
Appendix 2
Frequency domain Algorithms
% Analysing an intensity image by Fourieranalysis techniques%
load images
I=ind2gray(X,map); % Sample set
figure(1)
imshow(I)
%Fourier Analysis%
FI=fft2(I); % Complex amplitudes
SFI=fftshift(FI); % Origin in the middle of the matrix
SFI(130,176) is C0 in SFI
Ck=abs(SFI); % Amplitudes
AKE=log10(Ck+1);
figure(2)
imshow(Ck) % Amplitudes with the origin in the middle of the matrix
title('Amplitudes')
a=min(AKE(:));
b=max(AKE(:));
sAKE=(AKEa)/(ba); % Linearly scaled logarithms
figure(3)
imshow(sAKE)
title('Scaled amplitudes') % giving titles on the image
%Simulating Noise in an Image% 65
26  P a g e
MAT=SFI;
MAT(74,100)=800*MAT(74,100); %noise at the given coordinates
MAT(186,252)=800*MAT(186,252); %noise at the given coordinates
Ck=abs(MAT); % Amplitudes
AKE=log10(Ck+1);
a=min(AKE(:))
b=max(AKE(:))
sAKE=(AKEa)/(ba); % Linearly scaled logarithms
figure(4)
imshow(sAKE)
title('Scaled amplitudes')
IMG=ifft2(MAT);
figure(5)
imshow(abs(IMG))
%Ideal Low Pass Filter%
[m,n]=size(I);
M=zeros(m,n); % Initiating the low pass mask
M(130par:130+par,176par:176+par)=1;
fMAT=MAT.*M; % Filtering MAT
IMG2=ifft2(fMAT);
figure(6)
imshow(abs(IMG2))
%Mask as an Amplitude Spectrum of an Image%
figure(7) % Amplitude spectrum in frequency domain
subplot(2,1,1)
imshow(M)
subplot(2,1,2)
plot(M(130,:))
grid 66
27  P a g e
IMG3=fftshift(ifft2(M));
figure(8)
aIMG3=abs(IMG3);
a3=min(aIMG3(:));
b3=max(aIMG3(:));
sIMG3=(aIMG3a3)/(b3a3); % enhancing the image with max. and min.values % while
removing the rest of the frequency values
%Butterworth Low Pass Filter%
[V,U]=meshgrid(175:174,129:128);
D=sqrt(U.^2+V.^2);
H=1./(1+(D/D0).^(2*N)); % Butterworth Low Pass Filter
figure(9) % Amplitude spectrum in frequency domain
subplot(2,1,1)
imshow(H)
subplot(2,1,2)
plot(H(130,:))
grid
%Notch Filter%
D1=sqrt((U+56).^2+(V+76).^2);
D2=sqrt((U56).^2+(V76).^2);
H1=1./(1+(D1/D0).^(2*N)); %implementing the notch filter formula
H2=1./(1+(D2/D0).^(2*N)); %implementing the notch filter formula
figure(9)
imshow(D2/max(D2(:)))
Hlow=H1+H2; % Local low pass filter in pole positions
High=1Hlow;
figure(10)
imshow(High)
Inverse filter code
N=256;
n=.2;
f=freadbin('lenna.256',N,N);
figure(1)
imagesc(f)
colormap(gray)
b=ones(4,4)/4^2;
F=fft2(f);
B=fft2(b,N,N);
G=F.*B;
g=ifft2(G)+10*randn(N,N);
G=fft2(g);
figure(2)
imagesc(abs(ifft2(G)))
28  P a g e
colormap(gray)
BF=find(abs(B)<n);
%B(BF)=max(max(B))/1.5;
B(BF)=n;
H=ones(N,N)./B;
I=G.*H;
im=abs(ifft2(I));
figure(3)
imagesc(im)
colormap(gray)
Iterative method code
N=256;
lambda=0.1;
f=freadbin('lenna.256',N,N);
figure(1)
imagesc(f)
colormap(gray)
F=fft2(f);
b=ones(4,4)/16;
B=fft2(b,N,N);
G=F.*B;
%g=ifft2(G)+10*randn(N,N);
%G=fft2(g);
figure(2)
imagesc(abs(ifft2(G)))
colormap(gray)
K=lambda*G;
for l=1:1500,
if mod(l,25)==0
lambda=lambda/5;
end
A=GK.*B;
K=K+lambda*A;
if mod(l,50)==0
l
sum(sum(A))
figure(3)
imagesc(abs(ifft2(K)))
colormap(gray)
pause
end
end
29  P a g e