function [G,gabout] = gabor_edge(I,lambda,sigma,gamma,phi)
% I=sum(I,3);
if isa(I,'double')~=1 % Make sure image pixels stored as double
I = double(I);
end
phi=phi;
S=sigma;
r=gamma;
lanp=lambda;
N=31;
n=1;
r=1;
[C,D]=size(I);
for v=1:0.5:2
S=S*v;
lanp=lanp*v;
for u=0:1:5
theta=pi*u/6;
for x=-N:N-1
for y=-N:N-1
% for x=-fix(S):fix(S)
% for y=-fix(r*S):fix(r*S)
xprime=x*cos(theta)+y*sin(theta);
yprime=y*cos(theta)-x*sin(theta);
G=0.5/(pi*r*S^2)*exp(-.5*((xprime)^2+(yprime*r)^2)/(S^2))*(exp(i*2*pi*xprime/lanp+phi)-exp(-(S*2*pi/lanp)^2/2));
% G=0.5/(pi*r*S^2)*exp(-.5*((xprime)^2+(yprime*r)^2)/(S^2))*(exp(i*2*pi*sqrt(xprime^2+yprime^2)/lanp+phi)-exp(-S^2/2));
Gr(x+N+1,y+N+1)=real(G);
Gm(x+N+1,y+N+1)=imag(G);
Gb(x+N+1,y+N+1)=G;
end
end
Regabout(:,:,n)=conv2(I,double(Gr),'same');
Imgabout(:,:,n)=conv2(I,double(Gm),'same');
gabout(:,:,n)=conv2(I,double(Gb),'same');
gabout1(:,:,n) = sqrt(Imgabout(:,:,n).^2 + Regabout(:,:,n).^2);
figure(1);subplot(4,6,n),imshow(Gr,[]);
figure(2);subplot(4,6,n),imshow(Gm,[]);
figure(3);subplot(4,6,n),imshow(Gb,[]);
figure(4);subplot(4,6,n),imshow(Regabout(:,:,n),[]);
figure(5);subplot(4,6,n),imshow(Imgabout(:,:,n),[]);
figure(6);subplot(4,6,n),imshow(gabout(:,:,n),[]);
n=n+1;
end
end
% for c=1:C
% for d=1:D
% % for n=1:18
% f(c,d)=max(Regabout(c,d));
%
% % end
% end
% end
% figure(11);imshow(f);
Regabout_result=sum(Regabout,3);
Imgabout_result=sum(Imgabout,3);
gabout_result=sum(gabout,3);
gabout1_result = sum(gabout1,3);
% [a1,b1]=size(Regabout_result)
figure(7);imshow(Regabout_result,[]);
figure(8);imshow(Imgabout_result,[]);
figure(9);imshow(gabout_result);
figure(12);imshow(gabout1_result);
% % for c=1:C
% % for d=1:D
% % % if Regabout_result(c,d,3)<1
% % % Regabout_result=0;
% % % else Regabout_result=Regabout_result;
% % % end
% % end
% % end
% if sum(Regabout,3)<5.4
% Regabout_result=0;
% else Regabout_result=sum(Regabout,3)
% end
% figure(71);imshow(Regabout_result);
gabout = sqrt(Imgabout_result.^2 + Regabout_result.^2);