Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all

how can help me to combine firefly with watermarking ?

thanks

yours majid

please hurry up

please
Posted

1 solution

function [best]=firefly_simple(instr)
% n=????? ??? ??? ?? ???
% MaxGeneration=?????????????????? ????
if nargin<1, instr=[12 50]; end
n=instr(1); MaxGeneration=instr(2);
rand('state',0); % Reset the random generator
% ------ Four peak functions ---------------------
str1='exp(-(x-4)^2-(y-4)^2)+exp(-(x+4)^2-(y-4)^2)';
str2='+2*exp(-x^2-(y+4)^2)+2*exp(-x^2-y^2)';
funstr=strcat(str1,str2);
% ????? ?? ?? ???? ???? ???
f=vectorize(inline(funstr));
% range=[xmin xmax ymin ymax];
range=[-5 5 -5 5];

% ------------------------------------------------
alpha=0.2; % Randomness 0--1 (highly random)
gamma=1.0; % Absorption coefficient
% ------------------------------------------------
% ?????????? ??? ???? ????? ??????? ??????
Ngrid=100;
dx=(range(2)-range(1))/Ngrid;
dy=(range(4)-range(3))/Ngrid;
[x,y]=meshgrid(range(1):dx:range(2),...
range(3):dy:range(4));
z=f(x,y);
% ????? ?? ??? ???? ???
figure(1); surfc(x,y,z);

% ------------------------------------------------
% ????????? ???? ?? n??? ?????%
[xn,yn,Lightn]=init_ffa(n,range);
% ????? ??????? ??? ??? ?? ???
% contours of the function to be optimized
figure(2);
% Iterations or pseudo time marching
for i=1:MaxGeneration, %%%%% ???? ?????
% ????? ???? ????
contour(x,y,z,15); hold on;
% ??????? ??? ????? ????
zn=f(xn,yn);

% ???? ???? ??? ????? ?? ???? ????? ??? ???
[Lightn,Index]=sort(zn);
xn=xn(Index); yn=yn(Index);
xo=xn; yo=yn; Lighto=Lightn;
% ?????? ???? ??????? ?????? ?????
plot(xn,yn,'.','markersize',10,'markerfacecolor','g');
% ?????????????? ??????????????????
[xn,yn]=ffa_move(xn,yn,Lightn,xo,yo,Lighto,alpha,gamma,range);
drawnow;
hold off;
end %%%%% end of iterations
best(:,1)=xo'; best(:,2)=yo'; best(:,3)=Lighto';

% -----????????? ?????? ???????????????---------
% ???? ?????n ????????%
function [xn,yn,Lightn]=init_ffa(n,range)
xrange=range(2)-range(1);
yrange=range(4)-range(3);
xn=rand(1,n)*xrange+range(1);
yn=rand(1,n)*yrange+range(3);
Lightn=zeros(size(yn));

% ?????????????? ??????????????????
function [xn,yn]=ffa_move(xn,yn,Lightn,xo,yo,...
Lighto,alpha,gamma,range)
ni=size(yn,2); nj=size(yo,2);
for i=1:ni,
% The attractiveness parameter beta=exp(-gamma*r)
for j=1:nj,
r=sqrt((xn(i)-xo(j))^2+(yn(i)-yo(j))^2);
if Lightn(i)<lighto(j),>beta0=1; beta=beta0*exp(-gamma*r.^2);
xn(i)=xn(i).*(1-beta)+xo(j).*beta+alpha.*(rand-0.5);
yn(i)=yn(i).*(1-beta)+yo(j).*beta+alpha.*(rand-0.5);
end
end % end for j
end % end for i
[xn,yn]=findrange(xn,yn,range);

%?????????????????????????????????????????
function [xn,yn]=findrange(xn,yn,range)
for i=1:length(yn),
if xn(i)<=range(1), xn(i)=range(1); end
if xn(i)>=range(2), xn(i)=range(2); end
if yn(i)<=range(3), yn(i)=range(3); end
if yn(i)>=range(4), yn(i)=range(4); end
end
% ============== ?????=====================================
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900