-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestLBP_imperfectSeg.m
72 lines (64 loc) · 2.84 KB
/
testLBP_imperfectSeg.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
% If usage of this script contribute to scientific publication useful please cite the paper
% entitled 'Local Binary Pattern for word spotting in historical document' which
% can be found on 'https://arxiv.org/pdf/1604.05907v2.pdf'
% For citation
% @inproceedings{stauffer2016graph,
% title={Graph-based keyword spotting in historical handwritten documents},
% author={Stauffer, Michael and Fischer, Andreas and Riesen, Kaspar},
% booktitle={Joint IAPR International Workshops on Statistical Techniques in Pattern Recognition (SPR) and Structural and Syntactic Pattern Recognition (SSPR)},
% pages={564--573},
% year={2016},
% organization={Springer}
% }
clc;
global features labels
debug = false;
%% Preload the queries and target documents
[labels, qImgStruct] = loadDirCropped('../distortedGWnew/100/');
%% Features LBP extraction
qImgStruct = featLBPu2kdTree(qImgStruct, 1, 8, 13);
features = reshape([qImgStruct.featuresU2SP],size(qImgStruct(1).featuresU2SP,2),[])';
%% The initialisation
logmAP=zeros(100,1);
logAccuracy=zeros(100,1);
logrPrecision=zeros(100,1);
logP10 = zeros(100,1);
count=1;
if ~exist('dataResultDevelop','dir')
mkdir('./dataResultDevelop');
end
parfor folder=10:100
%% The feature extraction
[~, newStruct] = loadDirCropped(['/home/sounak/Desktop/distortedGWnew/' num2str(folder) '/']);
newStruct = featLBPu2kdTree(newStruct, 1, 8, 13);
featuresDB = reshape([newStruct.featuresU2SP],size(newStruct(1).featuresU2SP,2),[])';
%% The width cosideration
surface = [newStruct(:).width];
repSurface1 = repmat(surface',[1, numel(surface)]);
repSurface2 = repmat(surface,[numel(surface), 1]);
ratio1 = repSurface1./repSurface2;
ratio2 = repSurface2./repSurface1;
%% The coefficient calculation
k =1;
coeff = 0.15;
%% The ditance matrix calculation
dm=pdist2(features,featuresDB,'cityblock'); % citiblock distance
dm=dm./max(max(dm));
dm1 = (1-coeff)*dm+coeff*(1-min(ratio1, ratio2));
%% The calculation of the metrics
%[averagePrecision, meanAveragePrecision, recall, rprecision] = metricCalculation(dm1,labels);
[averagePrecision, meanAveragePrecision, recall, rprecision] = metricCalculation_self(dm1,labels);
%% The storing of the results
logmAP(folder) = meanAveragePrecision;
logAccuracy(folder) = mean(averagePrecision(:,1));
logrPrecision(folder) = rprecision;
logP10(folder) = mean(averagePrecision(:,10));
fname = ['./dataResultDevelop/LBP_Scorefiles_GW' num2str(folder) '.mat'];
fnameIn = ['./dataResultDevelop/LBP_Scoreindex_GW' num2str(folder) '.mat'];
%parforsave(fname,fnameIn,dm1);
end
%% Storing of the overall results
save('./GWlogmAP_LBP_self.mat','logmAP');
save('./GWloplogAccuracy_LBP_self.mat','logAccuracy');
save('./GWlogrPrecision_LBP_self.mat','logrPrecision');
save('./GWlogP10_LBP_self.mat','logP10');