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.
105 lines
2.8 KiB
Matlab
105 lines
2.8 KiB
Matlab
function stats=stats_ism_cars
|
|
thresholds=[0.5:0.2:4.5];
|
|
method{1}='Hough';method{2}='PC/BC-DIM';
|
|
spread=2
|
|
numTest=170;
|
|
|
|
%DEFINE CODEBOOK
|
|
load('ISM_codebook_cars.mat');
|
|
Locations=postprocess_codebook(Locations,patchClassList,spread);
|
|
[~,data_dir]=load_image_car(1,3);
|
|
|
|
%FOR EACH TEST IMAGE PERFORM ISM TO LOCATE CARS
|
|
disp(['Processing Images (',int2str(numTest),')'])
|
|
param{numTest}{length(method)}=[];%pre-allocate memory
|
|
for i=1:numTest
|
|
fprintf(1,'.%i.',i);
|
|
%load image and display
|
|
I = load_image_car(i-1,3);
|
|
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 CARS ARE LOCATED
|
|
filename='estimated_car_locations.txt';
|
|
stats{length(method)}=[];f1score{length(method)}=[];%pre-allocate memory
|
|
for m=1:length(method)
|
|
disp([method{m}]);
|
|
|
|
t=0;
|
|
for thres=thresholds.*m %*m to make thresholds larger for DIM
|
|
t=t+1;
|
|
disp(['***Testing Accuracy for threshold=',num2str(thres)])
|
|
|
|
%record results for current threshold into a file
|
|
file=fopen([data_dir,filename],'w');
|
|
for i=1:numTest
|
|
%find coordinates for which the votes exceed the threshold
|
|
index=find(param{i}{m}{1}(3,:)>thres);
|
|
coords=param{i}{m}{1}(1:2,index);
|
|
|
|
%store these coordinates in the results file
|
|
coords=convert_car_coordinates(coords);
|
|
write_result(i,coords,file);
|
|
end
|
|
fclose(file);
|
|
|
|
%evaluate the results using the java code supplied with the UIUC Cars dataset
|
|
dir=pwd;
|
|
cd(data_dir);
|
|
[status,result]=system(['java Evaluator trueLocations.txt ',filename])
|
|
stats{m}(t,:)=parse_car_evaluation(result);
|
|
cd(dir)
|
|
|
|
f1score{m}(t)=calc_f1score(stats{m}(t,:));
|
|
end
|
|
end
|
|
|
|
%PLOT THE RESULTS
|
|
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';
|
|
|
|
figured(11),clf
|
|
for m=1:length(method)
|
|
subplot(1,length(method),m),plot_errors(thresholds.*m,stats{m},max_error);title(method{m})
|
|
end
|
|
|
|
figured(12),clf
|
|
for m=1:length(method)
|
|
plot_precision_recall(stats{m},lineStyle{m}), hold on
|
|
end
|
|
legend(method,'Location','southeast')
|
|
|
|
figured(13),clf
|
|
for m=1:length(method)
|
|
plot_RFPPI(stats{m},lineStyle{m},numTest), hold on
|
|
end
|
|
legend(method,'Location','southeast')
|
|
|
|
|
|
|
|
function write_result(i,pos,file)
|
|
pos=pos(:);
|
|
fprintf(file,'%i: ',i-1);
|
|
if ~isnan(pos), fprintf(file,'(%i,%i) ',round(pos)); end
|
|
fprintf(file,'\n');
|
|
|
|
|
|
|
|
function stats=parse_car_evaluation(result)
|
|
vals=sscanf(result,'%*cCorrect detections :%u out of%u%');
|
|
TP=vals(1);
|
|
FN=vals(2)-vals(1);
|
|
|
|
ind=strfind(result,'False detections :');
|
|
FP=sscanf(result(ind:end),'False detections :%u');
|
|
|
|
stats=[TP,FP,FN]; |