Академический Документы
Профессиональный Документы
Культура Документы
Fourier Filtering
iltering Denoising Based on Genetic Algorithms
Jiahe Shi
Faculty of Communication Engineering, Qiushi H
Honor
onor College, Tianjin University
ABSTRACT
As the traditional filtering methods may cause the while the third edition of each generation about 2
problem of blur when applied on stripe
stripe-like images, minutes.
this paper raised a new method intending to solve the
problem, and provided the process of the method
development. The method, based on genetic II. Problem background
algorithms as well as two-dimensional
dimensional Fourier This method is mainly applied to the repair of stripe-
stripe
transform, offered a new perspective to denoise an like images
ages polluted by Gaussian noise. The general
image with
ith abundant components of high frequency, idea of filtering an image is to preserve its low
and is of certain significance. frequency component meanwhile remove the high
frequency component. For striped images (such as
Keywords : 2-D D Fourier transform, genetic zebra), the frequency domain of high frequency
algorithms, autocorrelations components is fairly abundant. The problem of image
imag
blur will emerge on conditions of direct filtering. So it
I. Operating Environment is necessary to adopt a new method for filtering.
This method is developed based on Matlab 2014b. In the preparation of each version of the program,
Corresponding or updated version is rrecommended ideas have undergone major changes, such as the
when verifying to ensure that the program runs shape of the filter. So parts of the Notes or other
normally. As the algorithm used a multi
multi-cycle, all statements that does not affect the results may be left
three versions of the program require much time. For in the program.
the first edition of the program, when the number of
individuals is only 10, running a generat
generation requires III. Methods
up to 10 minutes or so, the second version of the
program also takes about 6 minutes per generation, Firstly, the characteristics of the original image
spectrum and the noise image are analyzed, as shown
in the following figure.
@ IJTSRD
RD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug
Aug 2017 Page: 1142
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
2456
An image of zebra is used here. From the nature of the frequency component, it is also required a gradually
Fourier transform we know that the spectrum of the transition from ellipse to circle as the major axis
noise image is equal to the simple superposition of the increases. The parameters
rameters of the filter, i.e., the
noise spectrum and nd the image spectrum, i.e. direction of the ellipse, the initial eccentricity, the
velocity of the transition to the circle, the trend of the
F ( A + n) F ( A ) F (n); attenuation value, are used as the genes in the genetic
algorithm, and the optimal value is given by the
Thus, the noise spectrum "submerges" the spectrum of genetic algorithm.
the image. Since the noise spectrum is random and
unpredictable, we cannot completely restore the
image spectrum in thee frequency domain when the
noise spectrum is unknown, but only have the result
spectrum approached as close as possible to the
spectrum of the original image. This is the general
idea of this method. From the above graphs we can
see that the high-frequencyncy part of the original image
is obviously subsided, and after the noise is added, the
high-frequency
frequency region is obviously uplifted and
relatively flat. In the low frequency part, the original
image spectrum "terrain" is higher, making the
"submerged" effect ct of noise not significant. Namely
there is no obvious difference in the trend in the low
frequency part. Therefore, it is desirable to find a
filter function that best fits the image through a
genetic algorithm so that it can properly restore the
trend of the spectrum. Figure 3.3 example filter
The following figure shows the spectrum of the image In particular, taking the characteristics of abounding
flattened: high frequency components of the fringe image into
account, it is supposed to restore the high frequency
part of the spectral details as much as possible under
the prerequisite of ensuring that the image spectrum
trend approaches that of the original image. For the
question of how to extract the details of high
frequency components from the noise image, the
method of obtaining gradient radient information and
denoising with threshold is adopted in this method.
The gradient method is applied to extract the edge
information of the image, that is, the high frequency
component of the image. In this method, the gradient
of the image, the derivative
rivative (the difference) of the two
directions x and y , is calculated first, giving the
direction of the most grayscale change at each point.
The directional
ectional derivative (difference) is obtained
then for this direction, so that the edge information of
Figure 3.2 modulus of spectrum of source image, in ln the image can be obtained. When the image is added
20dB Noise, the image edge information is obtained as
In order to make the algorithm be generic, considering follows:
the characteristics of the image spectrum,
pectrum, the filter is
set to a series of concentric ellipses. In order to obtain
similar attenuation of the four corners of the high
@ IJTSRD
RD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug
Aug 2017 Page: 1143
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
2456
It can be seen that although the edge of the image is
also lost in some degree, it still retains part of the edge
information. With this part of the edge information
(rather than nothing at all), it will be possible to
modify the high-frequency
frequency spectrum, and thus try to
maximize the restoration of the details of the image.
In the process of designing this method, there are
three editions of program formed. The core idea of the
three editions is to use genetic algorithm to achieve
the optimal individual of filtering effect through
several iterations. For genetic algorithms, there must
be indicators that can be used to quantify the
restoration of individuals.. And the main difference
among the three editions of the program is that the
indicator is selected different. The versions are
Figure 3.4 example of edge information described here separately.
In order to restore as much as possible the noise
noise-free 3.1 The first edition of the program
high-frequency
frequency components from the information,
considering that the magnitude of "edge information" The evaluation indicator of the first edition of the
formed by the noise tends to be low, a threshold is set program is the sharpness of the central peak of the
thusly, ignoring the “edge information” where the autocorrelation function of the whole image. The
gray value is less than the threshold. The process following demonstrates its principles.
effect is as follows:
First the concept of two-dimensional
dimensional autocorrelation
function is explained. For m n order matrix:
a11 a1n
A= aij ain ;
am1 amj amn
@ IJTSRD
RD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug
Aug 2017 Page: 1144
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
2456
Referred to as A pq . Obviously, the fol following
expression is true for p and q :
p m
;
q n
1
R pq A A pq ;
mn
R A+n E (( A + n) ( A + n) pq )
E (( A + n ) ( A pq + n pq ))
E ( A A pq n n pq A n pq n A pq )
E (n A pq ) E (n pq A ) E (n) E ( A ) C ;
@ IJTSRD
RD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug
Aug 2017 Page: 1145
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
max( R ) eliminating the need for time-consuming
;
autocorrelation operation.
R
A Aij'
2
E (S A+n ) E (F (R A+n )) ij
i 1 j 1
E (S A ) E (Sn ) MSE ;
mn
There must be a non-negative expected value of the The following figure is the result of the first version
power spectrum. So E (S A+n ) can be regarded as the of the program with the number of individual
population set of 10, generations of 40, mutation rate
evaluation indicator. The lower value of the indicator
of 0.1, noise of 25dB . The program requires 71.2
indicates more ingredients of E (S n ) filtered in the minutes.
image, i.e. better filtering effect. In this way, only the
procedure of having the already calculated elements
of the spectrum squared and averaged is needed,
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1146
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
The following figure is the result of the second version of the program with the number of individual
population set of 10, generations of 40, mutation rate of 0.1, noise of 25dB . The program requires 48.4 minutes.
The following figure is the result of the third version of the program with the number of individual population
set of 10, generations of 40, mutation rate of 0.1, noise of 25dB . The program requires 6 minutes.
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1147
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1148
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
max_r = sqrt((XD/2)^2 +(YD/2)^2); dB = input('What intensity of noise are you
expecting?: ');
%max_S = XD*YD/4;
noise = wgn(XD, YD, dB);
%%
test = double(source) +noise;
%loading parameters
cal_t = fftshift(fft2(test));
disp(' ');
angle_t = exp(1i*angle(cal_t));
disp('Loading parameters...');
show_t = log(1 +abs(cal_t));
generation = input('For how many generations are you
expecting?: '); %overall generations of circulation in %%
GA
%extracting edge information
while(generation <= 1 || mod(generation, 1) ~= 0)
disp('Extracting edge information...');
disp('The parameter is supposed to be a positive
integer greater than 1'); [TestX,TestY]=gradient(test);
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1149
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
% [para_e, para_theta, para_velocity, para_2, para_1, grad_r(isnan(grad_r)) = 0;
para_range, para_threshold]
primitive_mark = max(grad_r(:))/std(grad_r(:));
%where para_range indicates the range of the filter's
value, para_threshold restricts the threshold for the R = repmat(R, 1, 1, 2*number);
matrix grad to be set to zero, as well as para_velocity
mark = primitive_mark*ones(1, 2*number);
indicates the speed from a elipse to transform to a
circle clear primitive_mark R_estimated
limits = [0, 0.9999; disp('Preparation accomplished, Launching the GA
circulation...');
0, pi;
disp(' ');
-1, 0;
figure('Menubar','none','Name','Result
-10, -2;
Monitor','NumberTitle','off');
0, 1;
set(gcf, 'position', [239, 344, 1083, 420]);
0, 1;
subplot(1, 2, 1);
0, 1];
handle_image = imshow(result(:, :, 1), []);
limits_range = limits(:, 2) -limits(:, 1);
title('Filtering Result');
%the limits of values of the paras are as follows:
subplot(2, 2, 2);
% para_e para_theta para_velocity para_1
handle_window = gca;
para_range para_threshold para_coef
area(best_mark, 'EdgeColor', [77/255, 144/255,
% [0, 1) [0, pi) [-1, 0] [-10, -2] [0,1] [0, 1]
21/255], 'FaceColor', [49/255, 171/255, 118/255],
[0, 1]
'YDataSource', 'best_mark');
index = ones(1, 2*number);
hold on;
para = repmat(para', 1, 2*number);
plot(best_mark, 'x', 'Color', [249/255, 71/255,
best_mark = nan(1, generation); 71/255], 'YDataSource', 'best_mark', 'LineWidth', 1);
R = xcorr2(test); xlabel('Generations');
R = R./std(R(:)); ylabel('Marks');
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1150
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
alpha(0.7); %%
xlim([1, XD]); %GA circulation
ylim([1, YD]); disp('Starting the first generation...');
zlim([0, 1]); tic;
set(gca, 'xtick', [], 'xticklabel', []); for t = 1 : generation
set(gca, 'ytick', [], 'yticklabel', []); %generating new population
camproj('perspective'); couple = randperm(number); %free mating
title('Filter'); for i = 1 : 2 : number
subplot(2, 6, 11); for node = 1 : size(para, 1)
colormap(gca, parula); %swap genes
mesh(show_f(:, :, 1), 'ZDataSource', 'show_f(:, :, if(round(rand))
1)');
para(node, i +number) = para(node, i);
xlim([1, XD]);
para(node, i +number +1) = para(node, i +1);
ylim([1, YD]);
else
zlim([min(show_t(:)), max(show_t(:))]);
para(node, i +number) = para(node, i +1);
set(gca, 'xtick', [], 'xticklabel', []);
para(node, i +number +1) = para(node, i);
set(gca, 'ytick', [], 'yticklabel', []);
end
camproj('perspective');
%mutation
title('Spectrum');
if(rand < mutate)
subplot(2, 6, 12);
para(node, i +number) = limits(node, 1)
colormap(gca, parula); +limits_range(node)*rand;
contour3(R(:, :, 1), 30,'ZDataSource', 'R(:, :, 1)'); end
box off; if(rand < mutate)
xlim([1, size(R, 1)]); para(node, i +number +1) = limits(node, 1)
+limits_range(node)*rand;
ylim([1, size(R, 2)]);
end
zlim(R_range);
end
set(gca, 'xtick', [], 'xticklabel', []);
clear node
set(gca, 'ytick', [], 'yticklabel', []);
end
camproj('perspective');
clear i;
title('Autocorrelation');
%characterizing individuals
drawnow;
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1151
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
for i = number +1 : 2*number %scoring
%filter generating R(:, :, i) = xcorr2(result(:, :, i));
for j = 1 : XD; R_temp = R(:, :, i);
for k = 1 : YD; R(:, :, i) = R_temp./std(R_temp(:));
ellipse = (1 -para(1, i)*cos(para(2, i))^2)*(j - [DiffX, DiffY] = gradient(R(:, :, i));
XD/2)^2 +(1 -para(1, i)*sin(para(2, i))^2)*(k -
YD/2)^2 +para(1, i)*sin(2*para(2, i))*(j -XD/2)*(k - bevel_r = sqrt(DiffX.^2 +DiffY.^2);
YD/2);
grad_r = DiffX.*(DiffX./bevel_r)
ellipse = pi*ellipse/sqrt(1 -(para(1, i)^2)); +DiffY.*(DiffY./bevel_r);
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1152
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
beep; %%
disp(' '); %reading the target image
%terminate circle disp('Loading raw image...');
if(t > 2) source = double(imread('zebra/Zebra.png'));
if(best_mark(t) == best_mark(t -1) && best_mark(t [XD,YD] = size(source);
-1) == best_mark(t -2))
max_r = sqrt((XD/2)^2 +(YD/2)^2);
break;
%%
end
%adding noise
end
disp(' ');
end
disp('Adding noise...');
%%
dB = input('What intensity of noise are you
%display result expecting?: ');
figure('Menubar','none','Name','Result while(isempty(dB))
comparasion','NumberTitle','off');
dB = input('Waiting for input...');
set(gcf, 'position', [239, 162, 1083, 601]);
end
subplot(1, 2, 1);
noise = wgn(XD, YD, dB);
imshow(test, [min(test(:)), max(test(:))]);
test = double(source) +noise;
title('Input Image');
cal_t = fftshift(fft2(test));
subplot(1, 2, 2);
angle_t = exp(1i*angle(cal_t));
imshow(result(:, :, 1), [min(test(:)), max(test(:))]);
show_t = log(1 +abs(cal_t));
title('Filtering Result');
%%
%clear ellipse a ratio portion element r circle square;
%loading parameters
6.2 The second edition of the program
disp(' ');
%%
disp('Loading parameters...');
%initializing
generation = input('For how many generations are you
clc; expecting?: '); %overall generations of circulation in
GA
disp('GA image filtering version 2.0');
while(generation <= 1 || mod(generation, 1) ~= 0)
disp(' ');
disp('The parameter is supposed to be a positive
disp('Initializing...'); integer greater than 1');
clear; generation = input('Please re-input the parameter:
');
close all;
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1153
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
end %the filter function is as following:
number = input('How many individuals are there in % h(x) = x^4 +para_1*x^2
the flock?: '); %number of individual
%h(x) ensures value at the center of the filter equals
while(number <= 0 || mod(number, 2) ~= 0) to 0, which will contrbute to the normalization
procession.
disp('The parameter is supposed to be a positive
even number'); para = [0.7, pi/3, -1, -10, 1, 0.36, 0.7];
number = input('Please re-input the parameter: '); %the vector of parameter is sequenced as the
following order:
end
% [para_e, para_theta, para_velocity, para_2, para_1,
mutate = input('What is the probability of mutation para_range, para_threshold]
supposed to be?: '); %probability of mutating
%where para_range indicates the range of the filter's
while(mutate <= 0 || mutate >= 1) value, para_threshold restricts the threshold for the
matrix grad to be set to zero, as well as para_velocity
disp('The parameter is supposed to be located
indicates the speed from a elipse to transform to a
between 0 & 1');
circle
mutate = input('Please re-input the parameter: ');
limits = [0, 0.9999;
end
0, pi;
%%
-1, 0;
%extracting edge information
-10, -2;
disp('Extracting edge information...');
0, 1;
[TestX,TestY]=gradient(test);
0, 1;
bevel_t = sqrt(TestX.^2+TestY.^2);
0, 1];
grad_t=TestX.*(TestX./bevel_t)+TestY.*(TestY./bev
limits_range = limits(:, 2) -limits(:, 1);
el_t);
%the limits of values of the paras are as follows:
grad_t(isnan(grad_t)) = 0;
% para_e para_theta para_velocity para_1
clear bevel_t TestX TestY;
para_range para_threshold para_coef
%%
% [0, 1) [0, pi) [-1, 0] [-10, -2] [0,1] [0, 1]
%GA preparation [0, 1]
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1154
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
result = repmat(test, 1, 1, 2*number); area(percentage, 'EdgeColor', 'none', 'FaceColor',
[49/255, 171/255, 118/255], 'YDataSource',
show_f = repmat(show_t, 1, 1, 2*number); 'percentage');
grad_show = repmat(grad_t, 1, 1, 2*number); set(gca, 'xtick', [], 'xticklabel', []);
power = (abs(fftshift(fft2(test)))).^2; set(gca, 'ytick', [], 'yticklabel', []);
primitive_mark = mean(power(:)); ylim([0, 1]);
mark = primitive_mark*ones(1, 2*number); title('Progress');
percentage = [0, 0]; subplot(3, 5, 3);
clear primitive_mark R_estimated colormap(gca, parula);
disp('Preparation accomplished, Launching the GA surf(filter(:, :, 1), 'ZDataSource', 'filter(:, :, 1)');
circulation...');
shading interp;
disp(' ');
alpha(0.7);
figure('Menubar','none','Name','Result
Monitor','NumberTitle','off'); xlim([1, XD]);
set(gcf, 'position', [237, 195, 1083, 650]); ylim([1, YD]);
subplot(3, 5, [1, 2, 6, 7]); zlim([0, 1]);
handle_image = imshow(result(:, :, 1), []); set(gca, 'xtick', [], 'xticklabel', []);
title('Filtering Result'); set(gca, 'ytick', [], 'yticklabel', []);
subplot(3, 11, 23:32); camproj('perspective');
handle_window = gca; title('Filter');
area(best_mark, 'EdgeColor', [77/255, 144/255, subplot(3, 5, 8);
21/255], 'FaceColor', [49/255, 171/255, 118/255],
'YDataSource', 'best_mark'); colormap(gca, parula);
title('Trend of Best Score among Generations'); set(gca, 'ytick', [], 'yticklabel', []);
xlabel('Generations'); camproj('perspective');
ylabel('Marks'); title('Spectrum');
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1155
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
title('Edge Information'); end
drawnow; clear i;
%% %characterizing individuals
%GA circulation for i = number +1 : 2*number
disp('Starting the first generation...'); percentage = [1, 1]*(i -number -
1)/number;refreshdata;drawnow;
tic;
%filter generating
for t = 1 : generation
for j = 1 : XD;
percentage = [0, 0];refreshdata;drawnow;
for k = 1 : YD;
%generating new population
ellipse = (1 -para(1, i)*cos(para(2, i))^2)*(j -
couple = randperm(number); %free mating XD/2)^2 +(1 -para(1, i)*sin(para(2, i))^2)*(k -
YD/2)^2 +para(1, i)*sin(2*para(2, i))*(j -XD/2)*(k -
for i = 1 : 2 : number
YD/2);
for node = 1 : size(para, 1)
ellipse = pi*ellipse/sqrt(1 -(para(1, i)^2));
%swap genes
circle = pi*((j -XD/2)^2 +(k -YD/2)^2);
if(round(rand))
%square = ((max(abs(j -XD/2), abs(k -
para(node, i +number) = para(node, i); YD/2)))^2);
para(node, i +number +1) = para(node, i); portion = para(3, i)*ratio^2 -(para(3, i) +1)*ratio
+1;
end
element = (portion*ellipse +(1 -
%mutation portion)*circle)/(max_r)^2/pi;
if(rand < mutate) %element = (portion*elipse/max_elipse +(1 -
portion)*square/max_S);
para(node, i +number) = limits(node, 1)
+limits_range(node)*rand; filter(j, k, i) = element^2 +para(4, i)*element;
end end
if(rand < mutate) clear k;
para(node, i +number +1) = limits(node, 1) end
+limits_range(node)*rand;
clear j;
end
filter(:, :, i) = filter(:, :, i)/max(max(abs(filter(:, :,
end i))))*para(5, i) +1;
clear node %profile modifying
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1156
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
grad_temp = grad_t; refreshdata;
grad_temp(grad_temp < (max(grad_temp(:)) drawnow;
+std(grad_temp(:)))*para(6, i)) = 0;
%informing
grad_show(:, :, i) = grad_temp;
disp(['Generation #',num2str(t),' has finished']);
cal_h = fftshift(fft2(grad_temp));
toc;
show_h = log(1 +abs(cal_h));
beep;
%filtering
disp(' ');
show_f(:, :, i) = show_t.*filter(:, :, i) +show_h.*(1 -
filter(:, :, i)); %terminate circle
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1157
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
clc; %%
disp('GA image filtering version 3.0'); %loading parameters
disp(' '); disp(' ');
disp('Initializing...'); disp('Loading parameters...');
clear; generation = input('For how many generations are you
expecting?: '); %overall generations of circulation in
close all; GA
%% while(generation <= 1 || mod(generation, 1) ~= 0)
%reading the target image disp('The parameter is supposed to be a positive
integer greater than 1');
disp('Loading raw image...');
generation = input('Please re-input the parameter:
source = double(imread('zebra/Zebra.png'));
');
[XD,YD] = size(source);
end
disp('Loading training sample...');
number = input('How many individuals are there in
test(:, :, 1) = double(imread('zebra/ZebraG the flock?: '); %number of individual
20_22.1947.png'));
while(number <= 0 || mod(number, 2) ~= 0)
test(:, :, 2) = double(imread('zebra/ZebraG
disp('The parameter is supposed to be a positive
30_18.8633.png'));
even number');
test(:, :, 3) = double(imread('zebra/ZebraG
number = input('Please re-input the parameter: ');
40_16.5752.png'));
end
test(:, :, 4) = double(imread('zebra/ZebraG
50_14.8842.png')); mutate = input('What is the probability of mutation
supposed to be?: '); %probability of mutating
test(:, :, 5) = double(imread('zebra/ZebraG
60_13.5614.png')); while(mutate <= 0 || mutate >= 1)
sample = size(test, 3) disp('The parameter is supposed to be located
between 0 & 1');
cal_t = test;
mutate = input('Please re-input the parameter: ');
angle_t = test;
end
show_t = test;
%%
for i = 1 : sample;
%extracting edge information
cal_t(:, :, i) = fftshift(fft2(test(:, :, i)));
disp(' ');
angle_t(:, :, i) = exp(1i*angle(cal_t(:, :, i)));
disp('Extracting edge information...');
show_t(:, :, i) = log(1 +abs(cal_t(:, :, i)));
grad_t = test;
end
for i = 1 : sample;
clear i;
[TestX,TestY]=gradient(test(:, :, i));
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1158
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
bevel_t = sqrt(TestX.^2+TestY.^2); index = ones(1, 2*number);
grad_t(:, :, para = repmat(para', 1, 2*number);
i)=TestX.*(TestX./bevel_t)+TestY.*(TestY./bevel_t);
best_mark = nan(1, generation);
end
mark_temp = zeros(1, sample);
grad_t(isnan(grad_t)) = 0;
mark_range = [0, 1];
clear bevel_t TestX TestY i;
filter = repmat(filter, 1, 1, 2*number);
%%
result = repmat(test, 1, 1, 1, 2*number);
%GA preparation
show_f = repmat(show_t, 1, 1, 1, 2*number);
disp(' ');
grad_show = repmat(grad_t, 1, 1, 1, 2*number);
disp('Initialization accomplished, preparing for the
GA circulation...'); show_h = zeros(XD, YD, sample);
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1159
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
f_show = f_show./sample; %box off;
figure('Menubar','none','Name','Result surf(filter(:, :, 1), 'ZDataSource', 'filter(:, :, 1)');
Monitor','NumberTitle','off');
shading interp;
set(gcf, 'position', [237, 195, 1083, 650]);
alpha(0.7);
subplot(3, 5, [1, 2, 6, 7]);
xlim([1, XD]);
handle_image = imshow(show_result, []);
ylim([1, YD]);
title('Filtering Result');
zlim([0, 1]);
subplot(3, 11, 23:32);
set(gca, 'xtick', [], 'xticklabel', []);
handle_window = gca;
set(gca, 'ytick', [], 'yticklabel', []);
area(best_mark, 'EdgeColor', [77/255, 144/255,
21/255], 'FaceColor', [49/255, 171/255, 118/255], camproj('perspective');
'YDataSource', 'best_mark');
title('Filter');
hold on;
subplot(3, 5, 8);
plot(best_mark, 'x', 'Color', [249/255, 71/255,
colormap(gca, parula);
71/255], 'YDataSource', 'best_mark', 'LineWidth', 1);
mesh(f_show, 'ZDataSource', 'f_show');
hold off;
xlim([1, XD]);
grid on;
ylim([1, YD]);
axis([1, generation, mark_range(1), mark_range(2)]);
zlim([min(show_t(:)), max(show_t(:))]);
title('Trend of Best Score among Generations');
set(gca, 'xtick', [], 'xticklabel', []);
xlabel('Generations');
set(gca, 'ytick', [], 'yticklabel', []);
ylabel('Marks');
camproj('perspective');
subplot(3, 11, 33);
title('Spectrum');
area(percentage, 'EdgeColor', 'none', 'FaceColor',
[49/255, 171/255, 118/255], 'YDataSource', subplot(3, 5, [4, 5, 9, 10]);
'percentage');
handle_grad = imshow(show_grad, []);
set(gca, 'xtick', [], 'xticklabel', []);
title('Edge Information');
set(gca, 'ytick', [], 'yticklabel', []);
drawnow;
ylim([0, 1]);
%%
title('Progress');
%GA circulation
subplot(3, 5, 3);
disp('Starting the first generation...');
colormap(gca, parula);
tic;
%contour3(filter(:, :, 1), 30, 'ZDataSource', 'filter(:, :,
1)'); for t = 1 : generation
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1160
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
percentage = [0, 0];refreshdata;drawnow; filter(j, k, i) = -circle^2 +para(1, i)*circle;
%generating new population end
couple = randperm(number); %free mating end
for i = 1 : 2 : number filter(:, :, i) = filter(:, :, i)/max(max(abs(filter(:, :,
i))))*para(2, i) +1;
for node = 1 : size(para, 1)
%profile modifying
%swap genes
for j = 1 : sample
if(round(rand))
grad_temp = grad_t(:, :, j);
para(node, i +number) = para(node, i);
grad_temp(grad_temp < (max(grad_temp(:))
para(node, i +number +1) = para(node, i +1); +std(grad_temp(:)))*para(3, i)) = 0;
else grad_show(:, :, j, i) = grad_temp;
para(node, i +number) = para(node, i +1); cal_h = fftshift(fft2(grad_temp));
para(node, i +number +1) = para(node, i); show_h(:, :, j) = log(1 +abs(cal_h));
end end
%mutation %filtering
if(rand < mutate) for j = 1 : sample
para(node, i +number) = limits(node, 1) show_f(:, :, j, i) = show_t(:, :, j).*filter(:, :, i)
+limits_range(node)*rand; +show_h(:, :, j).*(1 -filter(:, :, i)).*para(4, i);
end cal_f = (exp(show_f(:, :, j, i)) -1).*angle_t(:, :, j);
if(rand < mutate) result(:, :, j, i) = abs(ifft2(fftshift(cal_f)));
para(node, i +number +1) = limits(node, 1) end
+limits_range(node)*rand;
%scoring
end
for j = 1 : sample
end
diff_temp = result(:, :, j, i) - source;
end
mark_temp(j) = std(diff_temp(:));
%characterizing individuals
end
for i = number +1 : 2*number
mark(i) = mean(mark_temp);
percentage = [1, 1]*(i -
number)/number;refreshdata;drawnow; end
%filter generating %natual selecting
for j = 1 : XD; [mark, index] = sort(mark);
for k = 1 : YD; para = para(:, index);
circle = pi*((j -XD/2)^2 +(k -YD/2)^2); filter = filter(:, :, index);
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1161
International Journal of Trend in Scientific Research and Development (IJTSRD) ISSN: 2456-6470
grad_show = grad_show(:, :, :, index); if(best_mark(t) == best_mark(t -1) && best_mark(t
-1) == best_mark(t -2))
show_f = show_f(:, :, :, index);
break;
result = result(:, :, :, index);
end
best_mark(t) = mark(1);
end
%demonstrating champion
end
mark_range = minmax(best_mark);
%%
mark_range(1) = mark_range(1)*0.99;
%display result
mark_range(2) = mark_range(2)/0.99;
disp('Circulation terminated');
show_result = zeros(XD, YD);
figure('Menubar','none','Name','Result
show_grad = zeros(XD, YD); comparasion','NumberTitle','off');
for j = 1 : sample set(gcf, 'position', [237, 195, 1083, 650]);
show_result = show_result + result(:, :, j, 1); subplot(1, 2, 1);
show_grad = show_grad + grad_show(:, :, j, 1); imshow(source, []);
f_show = f_show + show_f(:, :, j, 1); title('Target Image');
end subplot(1, 2, 2);
show_result = show_result./sample; imshow(show_result, []);
show_grad = show_grad./sample; title('Filtering Result');
f_show = f_show./sample; %clear ellipse a ratio portion element r circle square;
set(handle_image, 'CData', show_result);
set(handle_grad, 'CData', show_grad);
set(handle_window, 'YLim', mark_range);
refreshdata;
drawnow;
%informing
disp(['Generation #',num2str(t),' has finished']);
toc;
beep;
disp(' ');
%terminate circle
if(t > 2)
@ IJTSRD | Available Online @ www.ijtsrd.com | Volume – 1 | Issue – 5 | July-Aug 2017 Page: 1162