You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.5 KiB
Matlab

function stats=stats_ism_usps
thresholds=[0.1:0.1:1.5]
method{1}='Hough';method{2}='PC/BC-DIM';
spread=2;
[images,classes,trainingIndeces,testingIndeces,numClasses]=load_data_usps;
testingIndeces=testingIndeces(1:200);
numTest=length(testingIndeces);
%DEFINE CODEBOOK
load('ISM_codebook_USPS.mat');
Locations=postprocess_codebook(Locations,patchClassList,spread);
%FOR EACH TEST IMAGE PERFORM ISM TO LOCATE DIGITS OF EACH CLASS
disp(['Processing Images (',int2str(numTest),')'])
for i=testingIndeces
fprintf(1,'.%i.',i);
%load image and display
I=preprocess_usps_image(images(i,:));
figured(2),clf, imagesc(I), hold on, axis('equal','tight'); title(' ');
colormap('gray');
%APPLY METHODS
[param{i}{1},param{i}{2}]=ism_compare_methods(I,patches,patchClassList,Locations,similarityThres);
end
%FOR EACH METHOD AND THRESHOLD TEST ACCURACY WITH WHICH IMAGES ARE CLASSIFIED
for m=1:length(method)
disp(' ');
disp(method{m});
disp('Testing Accuracy for threshold:')
t=0;
for thres=thresholds.*m
t=t+1;
fprintf(1,'.%2.2f.',thres);
stats{m}(t,:)=[0,0,0];
%FOR EACH TEST IMAGE DETERMINE CLASS
for i=testingIndeces
class=classes(i)
%analyse results as a detection tasks
for c=1:numClasses
index=find(param{i}{m}{c}(3,:)>thres);
coords{c}=param{i}{m}{c}(1:2,index);
amplitude{c}=param{i}{m}{c}(3,index);
end
stats{m}(t,:)=digits_evaluation(stats{m}(t,:),coords,class);
end
f1score{m}(t)=calc_f1score(stats{m}(t,:));
end
end
%PLOT THE RESULTS
disp(' ');
max_error=0;
for m=1:length(method)
max_error=max(max_error,max(sum(stats{m}(:,2:3),2)));
disp(['f1score ',method{m}]);
disp(f1score{m})
end
lineStyle{1}='b-s';lineStyle{2}='r-d';lineStyle{3}='g-o';lineStyle{4}='m-x';
figure(11),clf
for m=1:length(method)
subplot(1,length(method),m),plot_errors(thresholds.*m,stats{m},max_error);title(method{m})
end
figure(12),clf
for m=1:length(method)
plot_precision_recall(stats{m},lineStyle{m}), hold on
end
legend(method,'Location','southeast')
figure(13),clf
for m=1:length(method)
plot_RFPPI(stats{m},lineStyle{m},numTest), hold on
end
legend(method,'Location','southeast')
function stats=digits_evaluation(stats,pos,class)
numClasses=length(pos);
numPerClass=zeros(1,numClasses);
for c=1:numClasses
numPerClass(c)=size(pos{c},2);
end
numPerClass
%update counts of true positives, false positives, and false negatives
TP=0;FP=0;FN=0;
if numPerClass(class)>0
TP=1;
else
FN=1;
end
FP=sum(numPerClass)-TP;
stats=stats+[TP,FP,FN];