function [N]=srovnani(pic,T)
global G;global M;global G2;global M2;
pom = zeros(1,3); pom2 = zeros(1,3); matice = zeros(1,67); C = zeros(1,67);
for i=T 
        if i==44|i==45|i==49|i==52|i==56  % nemají 3. obrazek
             filename = ['Study01_000',num2str(i,'%02d'),'_002_registered.avi_average_image','.tif'];
          	 pic2 = imread(filename);
             pic2 = CutEdges(pic2);   
             pic2 = histeq(pic2); 
        
             posun(pic,pic2);
             posuninv(pic,pic2);
             
            if M<=M2 
                matice(i) = M;
            else
                matice(i) = M2;
            end
            
        elseif i==46|i==53
             filename = ['Study01_000',num2str(i,'%02d'),'_003_registered.avi_average_image','.tif'];
          	 pic2 = imread(filename);
             pic2 = CutEdges(pic2);   
             pic2 = histeq(pic2); 
        
             posun(pic,pic2);
             posuninv(pic,pic2);    
             
            if M<=M2 
                matice(i) = M;
            else
                matice(i) = M2;
            end
             
        else
           for j=2:3                % snímky jsou v pořádku
             filename = ['Study01_000',num2str(i,'%02d'),'_00',num2str(j),'_registered.avi_average_image','.tif'];
             pic2 = imread(filename);
             pic2 = CutEdges(pic2);   
             pic2 = histeq(pic2); 
        
             posun(pic,pic2);
             posuninv(pic,pic2);        
              
             pom(j)= M;
             pom2(j) = M2;
                                    
           end                        
             pom(1) = NaN;
             pom2(1) = NaN;
             
             [M,e] = min(pom);               % M = value, e = position
             [M2,e2] = min(pom2); 
             if M<=M2
                 matice(i) = M;
             else
                 matice(i) = M2;
             end
        
         end
           
end                                          % výsledný nález
matice(~matice) = inf;
[h,p] = min(matice);
 N = ['Study01_000',num2str(p,'%02d')]    
end