fname = dir('TESTDB/*.jpg');
len = size(fname,1);

img = cell(1,len);
imgEdge = cell(1,len);
imgNameAll = cell(1,len);
disp('.... begin load images');
for i=1:len
    imgName = ['TESTDB/',fname(i).name];
    str1 = ['........load  ',fname(i).name];
    disp(str1);
    img{i} = imread(imgName);
    imgCurr = rgb2gray(img{i});
    imgEdge{i} = edge(imgCurr,'canny');
    imgNameAll{i} = fname(i).name;
end

for type = 1:7
    if type == 1
        typeDistance = 'p1';
    end
    if type == 2
        typeDistance = 'p2';
    end
    if type == 3
        typeDistance = 'p3';
    end
    if type == 4
        typeDistance = 'p4';
    end
    if type == 5
        typeDistance = 'p5';
    end
    if type == 6
        typeDistance = 'cs';
    end
    if type == 7
        typeDistance = 'IS';
    end
    disp(typeDistance);
    
    fid = fopen('performance.txt','a');
    fprintf(fid,'%s  ',typeDistance);
    fprintf(fid,'\r\n');
    fclose(fid);
    
    fid1 = fopen('top5_ResultName.txt','a');
    fprintf(fid1,'%s  ',typeDistance);
    fclose(fid1);
    
    fid2 = fopen('top5_ResultIdex.txt','a');
    fprintf(fid2,'%s  ',typeDistance);
    fclose(fid2);
    
    
    for m =3:5:90
        for n=3:5:90
            
            fid1 = fopen('top5_ResultName.txt','a');
            fprintf(fid1,' m = %d ,n = %d ',m,n);
            fprintf(fid1,'\r\n');
            fclose(fid1);
            
            fid2 = fopen('top5_ResultIdex.txt','a');
            fprintf(fid2,' m = %d ,n = %d ',m,n);
            fprintf(fid2,'\r\n');
            fclose(fid2);
            
            fid = fopen('performance.txt','a');
            fprintf(fid,' m = %d ,n = %d ',m,n);
%             fprintf(fid,'\r\n');
            fclose(fid);
            
            strTemp = ['  m = ',num2str(m),'  n = ',num2str(n)];
            disp(strTemp);
            testPer(img,imgNameAll,len,m,n,typeDistance);        
        end
    end 
    
end