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.

78 lines
2.4 KiB
Matlab

function class_ism_usps
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 TEST ACCURACY WITH WHICH IMAGES ARE CLASSIFIED
for m=1:length(method)
disp(' ');
disp(method{m});
classError{m}=0;
k=0;
figured(10+m),clf
%FOR EACH TEST IMAGE DETERMINE CLASS
for i=testingIndeces
class=classes(i);
%analyse results as a classification task: find largest hough peak in each
%class, and classify image with class label corresponding to that largest peak
prob=zeros(1,numClasses);
for c=1:numClasses
maxAmplitude=max(param{i}{m}{c}(3,:));
if ~isempty(maxAmplitude)
prob(c)=maxAmplitude;
end
end
[~,predictedClass]=max(prob);
if predictedClass~=class
classError{m}=classError{m}+1;
fprintf(1,'Image %i: actual digit %i, predicted digit %i (error)\n',i,class-1,predictedClass-1);
k=k+1; plot_misclassified(m,i,k,images,class,predictedClass);
else
fprintf(1,'Image %i: actual digit %i, predicted digit %i\n',i,class-1,predictedClass-1);
end
end
end
%DISPLAY THE RESULT
disp(' ');
max_error=0;
for m=1:length(method)
disp(['% classification error ',method{m}]);
disp(100*classError{m}./numTest)
end
function plot_misclassified(m,i,k,images,classExpected,classPredicted)
figured(10+m)
maxsubplot(6,10,k);
imagesc(preprocess_usps_image(images(i,:)));
axis('equal','tight');
set(gca,'XTick',[],'YTick',[]);
digitExpected=classExpected-1;
digitPredicted=classPredicted-1;
text(0,1,int2str(digitExpected),'Units','normalized','VerticalAlignment','top','FontSize',12)
text(1,1,int2str(digitPredicted),'Units','normalized','VerticalAlignment','top','HorizontalAlignment','right','FontSize',12)
cmap=colormap('gray');cmap=1-cmap;colormap(cmap);