source2d=imread('sign.jpg');
colormap(gray);
imagesc(source2d);
figure;
s1=size(source2d)
%determine the lines
k=1;
for i=1:s1(1)
    for j=1:s1(2)
        if source2d(i,j)<150
            Line_dimention(k)=i;
        end
    end
    k=k+1;
end
sLD=size(Line_dimention)

%cut the line
k=1;
for i=1:sLD(2)
    if Line_dimention(i)~=0
       a(k)=Line_dimention(i);
       k=k+1;
   end   
end
slv=size(a);


k=1;j=1;
for i=2:slv(2)
    if a(i-1)~=0
        b(j,k)=a(i-1); 
        if (a(i)-a(i-1)>1)
            j=j+1;
            k=0;
        end
        k=k+1;
    end
end
b
h=minmax(b);
sh=size(h);
sb=size(b);
for i=1:sb(1)
    for j=1:sb(2)
        if b(i,j)==0
            b(i,j)=1111;
        end
    end
end
r=min(b,[],2);
for i=1:sh(1)
    h(i,1)=r(i);
end
h

       
for k=1:sh(1)
   switch k
       case{1}
           for i=h(1,1):h(1,2)
               for j=1:s1(2)
                   line1(i-(h(1,1)-1),j)=source2d(i,j);
               end
           end
           colormap(gray);
           image(line1);
           figure;
       case{2}
           for i=h(2,1):h(2,2)
               for j=1:s1(2)
                   line2(i-(h(2,1)-1),j)=source2d(i,j);
               end
           end
           colormap(gray);
           image(line2);
           figure;
       case{3}
           for i=h(3,1):h(3,2)
               for j=1:s1(2)
                   line3(i-(h(3,1)-1),j)=source2d(i,j);
               end
           end
           colormap(gray);
           image(line3);
           figure;
       case{4}
           for i=h(4,1):h(4,2)
               for j=1:s1(2)
                   line4(i-(h(4,1)-1),j)=source2d(i,j);
               end
           end
           colormap(gray);
           image(line4);
           figure;
       case{5}
           for i=h(5,1):h(5,2)
               for j=1:s1(2)
                   line5(i-(h(5,1)-1),j)=source2d(i,j);
               end
           end
           colormap(gray);
           image(line5);
           figure;
       case{6}
           for i=h(6,1):h(6,2)
               for j=1:s1(2)
                   line6(i-(h(6,1)-1),j)=source2d(i,j);
               end
           end
           colormap(gray);
           image(line6);
           figure;
       case{7}
           for i=h(7,1):h(7,2)
               for j=1:s1(2)
                   line7(i-(h(7,1)-1),j)=source2d(i,j);
               end
           end
           colormap(gray);
           image(line7);
           figure;
       case{8}
           for i=h(8,1):h(8,2)
               for j=1:s1(2)
                   line8(i-(h(8,1)-1),j)=source2d(i,j);
               end
           end
           colormap(gray);
           image(line8);
           figure;
       case{9}
           for i=h(9,1):h(9,2)
               for j=1:s1(2)
                   line9(i-(h(9,1)-1),j)=source2d(i,j);
               end
           end
           colormap(gray);
           image(line9);
           figure;
       case{10}
           for i=h(10,1):h(10,2)
               for j=1:s1(2)
                   line10(i-(h(10,1)-1),j)=source2d(i,j);
               end
           end
           colormap(gray);
           image(line10);
           figure;         
   end
end

imshow(line1); title('Original Signature');
ch1=size(line1);
    for i=1:ch1(2)
       minline=min(line1(1:ch1(1),i));
       if(minline<150)
           vert1=i; break;
       end
   end
   for i=ch1(2):-1:1
       minline=min(line1(1:ch1(1),i));
       if(minline<150)
           vert2=i; break;
       end
   end
%[vert1   vert2]
for j=vert1:vert2
    sig1(1:ch1(1),j+1-vert1)=line1(1:ch1(1),j);
end
imshow(sig1)
pause
%2-nd signatur
imshow(line2); title('Original Signature');
ch1=size(line2);
    for i=1:ch1(2)
       minline=min(line2(1:ch1(1),i));
       if(minline<150)
           vert1=i; break;
       end
   end
   for i=ch1(2):-1:1
       minline=min(line2(1:ch1(1),i));
       if(minline<150)
           vert2=i; break;
       end
   end
for j=vert1:vert2
    sig2(1:ch1(1),j+1-vert1)=line2(1:ch1(1),j);
end
imshow(sig2)
pause
%3-ed signatur
imshow(line3); title('Original Signature');
ch1=size(line3);
    for i=1:ch1(2)
       minline=min(line3(1:ch1(1),i));
       if(minline<150)
           vert1=i; break;
       end
   end
   for i=ch1(2):-1:1
       minline=min(line3(1:ch1(1),i));
       if(minline<150)
           vert2=i; break;
       end
   end
for j=vert1:vert2
    sig3(1:ch1(1),j+1-vert1)=line3(1:ch1(1),j);
end
imshow(sig3)
pause
%4-th signatur
imshow(line4); title('Original Signature');
ch1=size(line4);
    for i=1:ch1(2)
       minline=min(line4(1:ch1(1),i));
       if(minline<150)
           vert1=i; break;
       end
   end
   for i=ch1(2):-1:1
       minline=min(line4(1:ch1(1),i));
       if(minline<150)
           vert2=i; break;
       end
   end
for j=vert1:vert2
    sig4(1:ch1(1),j+1-vert1)=line4(1:ch1(1),j);
end
imshow(sig4)
pause
%5-th signatur
imshow(line5); title('Original Signature');
ch1=size(line5);
    for i=1:ch1(2)
       minline=min(line5(1:ch1(1),i));
       if(minline<150)
           vert1=i; break;
       end
   end
   for i=ch1(2):-1:1
       minline=min(line5(1:ch1(1),i));
       if(minline<150)
           vert2=i; break;
       end
   end
for j=vert1:vert2
    sig5(1:ch1(1),j+1-vert1)=line5(1:ch1(1),j);
end
imshow(sig5)
pause
%6-th signatur
imshow(line6); title('Original Signature');
ch1=size(line6);
    for i=1:ch1(2)
       minline=min(line6(1:ch1(1),i));
       if(minline<150)
           vert1=i; break;
       end
   end
   for i=ch1(2):-1:1
       minline=min(line6(1:ch1(1),i));
       if(minline<150)
           vert2=i; break;
       end
   end
for j=vert1:vert2
    sig6(1:ch1(1),j+1-vert1)=line6(1:ch1(1),j);
end
imshow(sig6)
pause
%7-th signatur
imshow(line7); title('Original Signature');
ch1=size(line7);
    for i=1:ch1(2)
       minline=min(line7(1:ch1(1),i));
       if(minline<150)
           vert1=i; break;
       end
   end
   for i=ch1(2):-1:1
       minline=min(line7(1:ch1(1),i));
       if(minline<150)
           vert2=i; break;
       end
   end
for j=vert1:vert2
    sig7(1:ch1(1),j+1-vert1)=line7(1:ch1(1),j);
end
imshow(sig7)
pause
%8-th signatur
imshow(line8); title('Original Signature');
ch1=size(line8);
    for i=1:ch1(2)
       minline=min(line8(1:ch1(1),i));
       if(minline<150)
           vert1=i; break;
       end
   end
   for i=ch1(2):-1:1
       minline=min(line8(1:ch1(1),i));
       if(minline<150)
           vert2=i; break;
       end
   end
for j=vert1:vert2
    sig8(1:ch1(1),j+1-vert1)=line8(1:ch1(1),j);
end
imshow(sig8)
pause
%9-th signatur
imshow(line9); title('Original Signature');
ch1=size(line9);
    for i=1:ch1(2)
       minline=min(line9(1:ch1(1),i));
       if(minline<150)
           vert1=i; break;
       end
   end
   for i=ch1(2):-1:1
       minline=min(line9(1:ch1(1),i));
       if(minline<150)
           vert2=i; break;
       end
   end
for j=vert1:vert2
    sig9(1:ch1(1),j+1-vert1)=line9(1:ch1(1),j);
end
imshow(sig9)
pause
%10-th signatur
imshow(line10); title('Original Signature');
ch1=size(line10);
    for i=1:ch1(2)
       minline=min(line10(1:ch1(1),i));
       if(minline<150)
           vert1=i; break;
       end
   end
   for i=ch1(2):-1:1
       minline=min(line10(1:ch1(1),i));
       if(minline<150)
           vert2=i; break;
       end
   end
for j=vert1:vert2
    sig10(1:ch1(1),j+1-vert1)=line10(1:ch1(1),j);
end
imshow(sig10)
pause
size(sig1)
%load target1.dat;  
T=eye(2,1000);
hig=20; len=50;
k = imresize(sig1, [hig  len], 'bicubic');
imshow(k)
pause
for i=1:hig
    for j=1:len
        km1((i-1)*len+j)=k(i,j);
    end
end
k = imresize(sig2, [hig  len], 'bicubic');
imshow(k)
pause
for i=1:hig
    for j=1:len
        km2((i-1)*len+j)=k(i,j);
    end
end
k = imresize(sig3, [hig  len], 'bicubic');
imshow(k)
pause
for i=1:hig
    for j=1:len
        km3((i-1)*len+j)=k(i,j);
    end
end
k = imresize(sig4, [hig  len], 'bicubic');
imshow(k)
pause
for i=1:hig
    for j=1:len
        km4((i-1)*len+j)=k(i,j);
    end
end
k = imresize(sig5, [hig  len], 'bicubic');
imshow(k)
pause
for i=1:hig
    for j=1:len
        km5((i-1)*len+j)=k(i,j);
    end
end
k = imresize(sig6, [hig  len], 'bicubic');
imshow(k)
pause
for i=1:hig
    for j=1:len
        km6((i-1)*len+j)=k(i,j);
    end
end
k = imresize(sig7, [hig  len], 'bicubic');
imshow(k)
pause
for i=1:hig
    for j=1:len
        km7((i-1)*len+j)=k(i,j);
    end
end
k = imresize(sig8, [hig  len], 'bicubic');
imshow(k)
pause
for i=1:hig
    for j=1:len
        km8((i-1)*len+j)=k(i,j);
    end
end
k = imresize(sig9, [hig  len], 'bicubic');
imshow(k)
pause
for i=1:hig
    for j=1:len
        km9((i-1)*len+j)=k(i,j);
    end
end
k = imresize(sig10, [hig  len], 'bicubic');
imshow(k)
pause
for i=1:hig
    for j=1:len
        km10((i-1)*len+j)=k(i,j);
    end
end

for j=1:1000
    i=1;  kall(i,j)=km1(j);
    i=2;  kall(i,j)=km2(j);
    i=3;  kall(i,j)=km3(j);
    i=4;  kall(i,j)=km4(j);
    i=5;  kall(i,j)=km5(j);
    i=6;  kall(i,j)=km6(j);
    i=7;  kall(i,j)=km7(j);
    i=8;  kall(i,j)=km8(j);
    i=9;  kall(i,j)=km9(j);
    i=10; kall(i,j)=km10(j);
    
end   
load target1.dat
kml=target1(:,:)

% get stop time
stop_time = cputime;
start_time=0;
% obtain the execution time of the program
execution_time = stop_time - start_time;

% display the execution time of the program
disp('Execution Time: ');
disp('--------------');
execution_time
load target1.dat;
I1 = 20;   % matrix size
T=target1(:,:);

pause
kall=double(kall');
T=target1;
S1=16;
[R,Q] = size(i);
[S2,Q1] = size(T)
P = kall;
P=double(P);
% Adaptive learning Algorithm
net=newff(minmax(P),[S1 S2],{'tansig','purelin'},'traingda');  
net.trainParam.show = 20;
net.trainParam.lr = 0.04;
net.trainParam.lr_inc = 1.0;
net.trainParam.epochs = 10000;
net.trainParam.goal = 0.01;
[net,tr]=train(net,P,T);

P1=double(km1');
Y=sim(net,P1)
tag=max(Y)
if tag==Y(1)
    imshow(sig1)
    title('Signature of RAED');
end
pause
P2=double(km2');
Y=sim(net,P2)
tag=max(Y)
if tag==Y(2)
      imshow(sig2)
    title('Signature of JEBREEL');
end
pause
P3=double(km3');
Y=sim(net,P3)
tag=max(Y)
if tag==Y(3)
    imshow(sig3)
    title('Signature of AHMAD');
end
pause
P4=double(km4');
Y=sim(net,P4)
tag=max(Y)
if tag==Y(4)
    imshow(sig4)
    title('Signature of SHAHER');
end
pause
P5=double(km5');
Y=sim(net,P5)
tag=max(Y)
if tag==Y(5)
    imshow(sig5)
    title('Signature of ZAED');
end
pause
P6=double(km6');
Y=sim(net,P6)
tag=max(Y)
if tag==Y(6)
    imshow(sig6)
    title('Signature of ALI');
end
pause
P7=double(km7');
Y=sim(net,P7)
tag=max(Y)
if tag==Y(7)
    imshow(sig7)
    title('Signature of ANWER');
end
pause
P8=double(km8');
Y=sim(net,P8)
tag=max(Y)
if tag==Y(8)
    imshow(sig8)
    title('Signature of OSAMA');
end
pause
P9=double(km9');
Y=sim(net,P9)
tag=max(Y)
if tag==Y(9)
    imshow(sig9)
    title('Signature of YASER');
end
pause
P10=double(km10');
Y=sim(net,P10)
tag=max(Y)
if tag==Y(10)
    imshow(sig10)
    title('Signature of SAMER');
end
if tag<0.70 & tag>0.50
    h=msgbox('most propably recognized                                     !!','high level of noise');
elseif tag<=0.50 
    h=msgbox('may not recognized                                           !!','low recognition rate');
end

% get stop time
stop_time = cputime;
% obtain the execution time of the program
execution_time = stop_time - start_time;

% display the execution time of the program
disp('Execution Time: ');
disp('--------------');
execution_time











