%Programm zur Berechnung der Laws Werte zur Klassifikation

%1x3 Matrizes
l      =       [  1     2       1  ];
e      =       [ -1     0       1  ];
s      =       [ -1     2      -1  ];

%1x5 Matrizes
l5      =       [  1     4       6       4       1 ]; 
e5      =       [ -1    -2       0       2       1 ]; 
s5      =       [ -1     0       2       0      -1 ];
r5      =       [  1    -4       6      -4       1 ];
w5      =       [ -1     2       0      -2       1 ];

%1x7 Matrizes
l7      =       [  1     6      15      20      15      6      1  ];
e7      =       [ -1    -4      -5       0       5      4      1  ];
s7      =       [ -1    -2       1       4       1     -2     -1  ];
r7      =       [ -1    -2      -1       4      -1     -2      1  ];
w7      =       [ -1     0       3       0      -3      0      1  ];
o7      =       [ -1     6     -15      20     -15      6     -1  ];


%Calculation with 5x5 Matrizes

%cd Negative

liste_neg = dir('Negative/*.bmp');
liste_pos = dir('Positive/*.bmp');

length_neg = length(liste_neg);

overall_length = length_neg  + length(liste_pos);

x = zeros(overall_length,14);
y = zeros(overall_length,1);

cd Negative
for i = 1:length(liste_neg)
      fprintf('%d\n',i);
      image = imread(liste_neg(i).name);
      image = rgb2gray(image);
   
    %Calculate Filtered Images
    image_l5l5 = conv2(double(image),l5,'same');
    image_l5e5 = conv2(image_l5l5,e5','same');
    image_l5s5 = conv2(image_l5l5,s5','same');
    image_l5r5 = conv2(image_l5l5,r5','same');
    image_l5w5 = conv2(image_l5l5,w5','same');
    image_l5l5 = conv2(image_l5l5,l5','same');
    
    image_e5e5 = conv2(double(image),e5,'same');
    image_e5l5 = conv2(image_e5e5,l5','same');
    image_e5s5 = conv2(image_e5e5,s5','same');
    image_e5r5 = conv2(image_e5e5,r5','same');
    image_e5w5 = conv2(image_e5e5,w5','same');
    image_e5e5 = conv2(image_e5e5,e5','same');
    
    image_s5s5 = conv2(double(image),s5,'same');
    image_s5l5 = conv2(image_s5s5,l5','same');
    image_s5e5 = conv2(image_s5s5,e5','same');
    image_s5r5 = conv2(image_s5s5,r5','same');
    image_s5w5 = conv2(image_s5s5,w5','same');
    image_s5s5 = conv2(image_s5s5,s5','same');
    
    
    image_r5r5 = conv2(double(image),r5,'same');
    image_r5l5 = conv2(image_r5r5,l5','same');
    image_r5e5 = conv2(image_r5r5,e5','same');
    image_r5s5 = conv2(image_r5r5,s5','same');
    image_r5w5 = conv2(image_r5r5,w5','same');
    image_r5r5 = conv2(image_r5r5,r5','same');
    
    image_w5w5 = conv2(double(image),w5,'same');
    image_w5l5 = conv2(image_w5w5,l5','same');
    image_w5e5 = conv2(image_w5w5,e5','same');
    image_w5s5 = conv2(image_w5w5,s5','same');
    image_w5r5 = conv2(image_w5w5,r5','same');
    image_w5w5 = conv2(image_w5w5,w5','same');
    
    
    %DIVIDE
    image_l5e5T = image_l5e5 ./ image_l5l5;
    image_l5s5T = image_l5s5 ./ image_l5l5;
    image_l5r5T = image_l5r5 ./ image_l5l5;
    image_l5w5T = image_l5w5 ./ image_l5l5;
    
    image_e5e5T = image_e5e5 ./ image_l5l5;
    image_e5l5T = image_e5l5 ./ image_l5l5;
    image_e5s5T = image_e5s5 ./ image_l5l5;
    image_e5r5T = image_e5r5 ./ image_l5l5;
    image_e5w5T = image_e5w5 ./ image_l5l5;
    
    image_s5s5T = image_s5s5 ./ image_l5l5; 
    image_s5l5T = image_s5l5 ./ image_l5l5;
    image_s5e5T = image_s5e5 ./ image_l5l5;
    image_s5r5T = image_s5r5 ./ image_l5l5;
    image_s5w5T = image_s5w5 ./ image_l5l5;
    
    image_r5r5T = image_r5r5 ./ image_l5l5;
    image_r5l5T = image_r5l5 ./ image_l5l5;
    image_r5e5T = image_r5e5 ./ image_l5l5;
    image_r5s5T = image_r5s5 ./ image_l5l5;
    image_r5w5T = image_r5w5 ./ image_l5l5;
    
    image_w5w5T = image_w5w5 ./ image_l5l5;
    image_w5l5T = image_w5l5 ./ image_l5l5;
    image_w5e5T = image_w5e5 ./ image_l5l5;
    image_w5s5T = image_w5s5 ./ image_l5l5;
    image_w5r5T = image_w5r5 ./ image_l5l5;
    
    
    %RT
    E5L5TR = image_e5l5T + image_l5e5T;
    S5L5TR = image_s5l5T + image_l5s5T;
    W5L5TR = image_w5l5T + image_l5w5T;
    R5L5TR = image_r5l5T + image_l5r5T;
    S5E5TR = image_s5e5T + image_e5s5T;
    W5E5TR = image_w5e5T + image_e5w5T;
    R5E5TR = image_r5e5T + image_e5r5T;
    W5S5TR = image_w5s5T + image_s5w5T;
    R5S5TR = image_r5s5T + image_s5r5T;
    R5W5TR = image_r5w5T + image_w5r5T;
    
    E5E5TR = image_e5e5T * 2;
    S5S5TR = image_s5s5T * 2;
    W5W5TR = image_w5w5T * 2;
    R5R5TR = image_r5r5T * 2;
    
    
    %Calculate STDV
    %{
    E5L5TR_std = std2(E5L5TR);
    S5L5TR_std = std2(S5L5TR);
    W5L5TR_std = std2(W5L5TR);
    R5L5TR_std = std2(R5L5TR);
    S5E5TR_std = std2(S5E5TR);
    W5E5TR_std = std2(W5E5TR);
    R5E5TR_std = std2(R5E5TR);
    W5S5TR_std = std2(W5S5TR);
    R5S5TR_std = std2(R5S5TR);
    R5W5TR_std = std2(R5W5TR);
    
    E5E5TR_std = std2(E5E5TR);
    S5S5TR_std = std2(S5S5TR);
    W5W5TR_std = std2(W5W5TR);
    R5R5TR_std = std2(R5R5TR);
    %}
    
    x(i,1) = std2(E5L5TR);
    x(i,2) = std2(S5L5TR);
    x(i,3) = std2(W5L5TR);
    x(i,4)= std2(R5L5TR);
    x(i,5)= std2(S5E5TR);
    x(i,6)= std2(W5E5TR);
    x(i,7)= std2(R5E5TR);
    x(i,8)= std2(W5S5TR);
    x(i,9)= std2(R5S5TR);
    x(i,10)= std2(R5W5TR);
    
    x(i,11)= std2(E5E5TR);
    x(i,12)= std2(S5S5TR);
    x(i,13)= std2(W5W5TR);
    x(i,14)= std2(R5R5TR);
    y(i) = -1;
    
   
  %  fprintf(Datei,'+1 1:%f 2:%f 3:%f 4:%f 5:%f 6:%f 7:%f 8:%f 9:%f 10:%f 11:%f 12:%f 13:%f 14:%f\n',E5L5TR_std,S5L5TR_std,W5L5TR_std,R5L5TR_std,S5E5TR_std,W5E5TR_std,R5E5TR_std,W5S5TR_std,R5S5TR_std,R5W5TR_std,E5E5TR_std,S5S5TR_std,W5W5TR_std,R5R5TR_std);
 
end
cd ..
%fclose(Datei);
cd Positive
pos = length_neg;
for i = 1:length(liste_pos)
    fprintf('2: %d\n',i);
      image = imread(liste_pos(i).name);
   
    %Calculate Filtered Images
    image_l5l5 = conv2(double(image),l5,'same');
    image_l5e5 = conv2(image_l5l5,e5','same');
    image_l5s5 = conv2(image_l5l5,s5','same');
    image_l5r5 = conv2(image_l5l5,r5','same');
    image_l5w5 = conv2(image_l5l5,w5','same');
    image_l5l5 = conv2(image_l5l5,l5','same');
    
    image_e5e5 = conv2(double(image),e5,'same');
    image_e5l5 = conv2(image_e5e5,l5','same');
    image_e5s5 = conv2(image_e5e5,s5','same');
    image_e5r5 = conv2(image_e5e5,r5','same');
    image_e5w5 = conv2(image_e5e5,w5','same');
    image_e5e5 = conv2(image_e5e5,e5','same');
    
    image_s5s5 = conv2(double(image),s5,'same');
    image_s5l5 = conv2(image_s5s5,l5','same');
    image_s5e5 = conv2(image_s5s5,e5','same');
    image_s5r5 = conv2(image_s5s5,r5','same');
    image_s5w5 = conv2(image_s5s5,w5','same');
    image_s5s5 = conv2(image_s5s5,s5','same');
    
    
    image_r5r5 = conv2(double(image),r5,'same');
    image_r5l5 = conv2(image_r5r5,l5','same');
    image_r5e5 = conv2(image_r5r5,e5','same');
    image_r5s5 = conv2(image_r5r5,s5','same');
    image_r5w5 = conv2(image_r5r5,w5','same');
    image_r5r5 = conv2(image_r5r5,r5','same');
    
    image_w5w5 = conv2(double(image),w5,'same');
    image_w5l5 = conv2(image_w5w5,l5','same');
    image_w5e5 = conv2(image_w5w5,e5','same');
    image_w5s5 = conv2(image_w5w5,s5','same');
    image_w5r5 = conv2(image_w5w5,r5','same');
    image_w5w5 = conv2(image_w5w5,w5','same');
    
    
    %DIVIDE
    image_l5e5T = image_l5e5 ./ image_l5l5;
    image_l5s5T = image_l5s5 ./ image_l5l5;
    image_l5r5T = image_l5r5 ./ image_l5l5;
    image_l5w5T = image_l5w5 ./ image_l5l5;
    
    image_e5e5T = image_e5e5 ./ image_l5l5;
    image_e5l5T = image_e5l5 ./ image_l5l5;
    image_e5s5T = image_e5s5 ./ image_l5l5;
    image_e5r5T = image_e5r5 ./ image_l5l5;
    image_e5w5T = image_e5w5 ./ image_l5l5;
    
    image_s5s5T = image_s5s5 ./ image_l5l5; 
    image_s5l5T = image_s5l5 ./ image_l5l5;
    image_s5e5T = image_s5e5 ./ image_l5l5;
    image_s5r5T = image_s5r5 ./ image_l5l5;
    image_s5w5T = image_s5w5 ./ image_l5l5;
    
    image_r5r5T = image_r5r5 ./ image_l5l5;
    image_r5l5T = image_r5l5 ./ image_l5l5;
    image_r5e5T = image_r5e5 ./ image_l5l5;
    image_r5s5T = image_r5s5 ./ image_l5l5;
    image_r5w5T = image_r5w5 ./ image_l5l5;
    
    image_w5w5T = image_w5w5 ./ image_l5l5;
    image_w5l5T = image_w5l5 ./ image_l5l5;
    image_w5e5T = image_w5e5 ./ image_l5l5;
    image_w5s5T = image_w5s5 ./ image_l5l5;
    image_w5r5T = image_w5r5 ./ image_l5l5;
    
    
    %RT
    E5L5TR = image_e5l5T + image_l5e5T;
    S5L5TR = image_s5l5T + image_l5s5T;
    W5L5TR = image_w5l5T + image_l5w5T;
    R5L5TR = image_r5l5T + image_l5r5T;
    S5E5TR = image_s5e5T + image_e5s5T;
    W5E5TR = image_w5e5T + image_e5w5T;
    R5E5TR = image_r5e5T + image_e5r5T;
    W5S5TR = image_w5s5T + image_s5w5T;
    R5S5TR = image_r5s5T + image_s5r5T;
    R5W5TR = image_r5w5T + image_w5r5T;
    
    E5E5TR = image_e5e5T * 2;
    S5S5TR = image_s5s5T * 2;
    W5W5TR = image_w5w5T * 2;
    R5R5TR = image_r5r5T * 2;
    
    
    %Calculate STDV
    %{
    E5L5TR_std = std2(E5L5TR);
    S5L5TR_std = std2(S5L5TR);
    W5L5TR_std = std2(W5L5TR);
    R5L5TR_std = std2(R5L5TR);
    S5E5TR_std = std2(S5E5TR);
    W5E5TR_std = std2(W5E5TR);
    R5E5TR_std = std2(R5E5TR);
    W5S5TR_std = std2(W5S5TR);
    R5S5TR_std = std2(R5S5TR);
    R5W5TR_std = std2(R5W5TR);
    
    E5E5TR_std = std2(E5E5TR);
    S5S5TR_std = std2(S5S5TR);
    W5W5TR_std = std2(W5W5TR);
    R5R5TR_std = std2(R5R5TR);
    %}
    pos = pos+1;
    x(pos,1) = std2(E5L5TR);
    x(pos,2) = std2(S5L5TR);
    x(pos,3) = std2(W5L5TR);
    x(pos,4)= std2(R5L5TR);
    x(pos,5)= std2(S5E5TR);
    x(pos,6)= std2(W5E5TR);
    x(pos,7)= std2(R5E5TR);
    x(pos,8)= std2(W5S5TR);
    x(pos,9)= std2(R5S5TR);
    x(pos,10)= std2(R5W5TR);
    
    x(pos,11)= std2(E5E5TR);
    x(pos,12)= std2(S5S5TR);
    x(pos,13)= std2(W5W5TR);
    x(pos,14)= std2(R5R5TR);
    y(pos) = +1;
    
   
  %  fprintf(Datei,'+1 1:%f 2:%f 3:%f 4:%f 5:%f 6:%f 7:%f 8:%f 9:%f 10:%f 11:%f 12:%f 13:%f 14:%f\n',E5L5TR_std,S5L5TR_std,W5L5TR_std,R5L5TR_std,S5E5TR_std,W5E5TR_std,R5E5TR_std,W5S5TR_std,R5S5TR_std,R5W5TR_std,E5E5TR_std,S5S5TR_std,W5W5TR_std,R5R5TR_std);
  
     
    
    
end

cd ..