-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyseBoutonsNewData.m
170 lines (140 loc) · 5.45 KB
/
analyseBoutonsNewData.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
%% Analyse boutons
clear all;close all;
%Initialization
Parameters.boutonMaskSize = 25;
Parameters.distThresh = 10;
Parameters.descriptor = 'Gabor';
Parameters.interestPointDetector = 'SURF';
sizeBouton = 25*25;
%Get images to be analysed
[~, meanImage, ~, ~, numFiles, ~] = readTIFfiles();
sizeImage = size(meanImage{1},1)*size(meanImage{1},2);
%% Get detected bouton centroids
tic
for n = 1:numFiles
tic
[boutonLocations{n},boutonScore(n)] = svmBoutonDetection(meanImage{n}, Parameters);
scoreMax(n,1)= boutonScore(n).scoreMax;
scoreMax(n,2)=abs(boutonScore(n).scoreMin);
disp (n);
close all;
toc
end
scoreMax = max(max(scoreMax));
toc
%% save
%save('boutonLocations-AllPoints10-1.mat', 'finalLocations', 'boutonLocations', 'detectorLocations', 'boutonScore')
%% find max scores
for n = 1:numFiles
scoreMax(n,1)= boutonScore(n).scoreMax;
scoreMax(n,2)=abs(boutonScore(n).scoreMin);
end
scoreMax = max(max(scoreMax));
%% Iterate over bouton score thresholds
%Initialize
boutonScoreThresh = linspace(-1.0001,1.0001,10000); %linspace(-0.2,0.1,100);
%best for 10000- 4801
%best for 100- location 66, [-0.00303030303030299], F1: 0.8414, accuracy:
%0.7871
%best for Gabor 10k-[-0.0257051405140514] f1=0.8398
accuracyPerImage = zeros(length(boutonScoreThresh),1);
TPRPerImage = zeros(length(boutonScoreThresh),1);
FPRPerImage = zeros(length(boutonScoreThresh),1);
accuracyPerBouton = zeros(length(boutonScoreThresh),1);
TPRPerBouton = zeros(length(boutonScoreThresh),1);
precisionAll = zeros(length(boutonScoreThresh),1);
F1all = zeros(length(boutonScoreThresh),1);
ik = 1; %keep track of iterations
for k = boutonScoreThresh(5027)%(4994)
for n = 1: numFiles
finalLabels = (boutonScore(n).score ./scoreMax) > k ;
finalBoutons{n} = boutonLocations{n}(finalLabels,:);
end
%% get accuracy and plot
%[labelledImages] = extractTestBoutons('test data2- 20 images'); %('TestData1- 46 images');
[labelledImages] = extractTestBoutons('NewDataGroundTruthLabels1.mat'); %labels of new data
[labelledEPBscore] = extractEPBscoreBoutons('NewData- EPBscore.mat');
accuracy = zeros(numFiles,1);
TPR = zeros(numFiles,1);
FPR = zeros(numFiles,1);
TP = zeros(numFiles,1);
FP = zeros(numFiles,1);
FN = zeros(numFiles,1);
F1 = zeros(numFiles,1);
precision = zeros(numFiles,1);
numBoutons = zeros(numFiles,1);
EPBscoreAccuracy = zeros(numFiles,1);
EPBscoreF1 = zeros(numFiles,1);
EPBscorePrecision= zeros(numFiles,1);
EPBscoreTPR = zeros(numFiles,1);
for i = 1:numFiles
currBoutons = finalBoutons{1,i};
labelledBoutons = labelledImages(i).boundingbox;
EPBscoreBoutons = labelledEPBscore(i).coord;
numInterestPointsEPBscore = size(labelledEPBscore(i).coord,1);
%Get scores of detected boutons
score(i) = scoreBoutons(currBoutons,labelledBoutons, sizeImage, sizeBouton);
EPBscore(i) = scoreBoutons(EPBscoreBoutons,labelledBoutons, sizeImage, sizeBouton);
accuracy(i) = score(i).accuracy;
EPBscoreAccuracy(i) = EPBscore(i).accuracy;
TPR(i) = score(i).TPR;
FPR(i) = score(i).FPR;
TP(i) = score(i).TP;
FP(i) = score(i).FP;
FN(i) = score(i).FN;
numBoutons(i) = score(i).numTrueBoutons;
F1(i) = score(i).F1;
precision(i) = score(i).precision;
EPBscoreF1(i) = EPBscore(i).F1;
EPBscorePrecision(i) = EPBscore(i).precision;
EPBscoreTPR(i) = EPBscore(i).TPR;
%Plot detected boutons and a rectangle around the True Positives
w = labelledImages(i).width(:);
h = labelledImages(i).height(:);
x = labelledImages(i).boundingbox(:,1);
y = labelledImages(i).boundingbox(:,3);
if 1
figure; imagesc(meanImage{i}); colormap(gray); axis off; %title('Bouton detection after SVM');
hold on
plot(currBoutons(:,1),currBoutons(:,2),'m+')
for j = 1:length(x)
rectangle('Position',[x(j),y(j),w(j),h(j)], 'LineWidth',2, 'EdgeColor', 'w');
end
plot(EPBscoreBoutons(:,1),EPBscoreBoutons(:,2),'c+')
for j = 1:length(x)
rectangle('Position',[x(j),y(j),w(j),h(j)], 'LineWidth',2, 'EdgeColor', 'w');
end
hold off
end
end
%Accuracy measures
EPBscoreAccuracyPerImage = mean(EPBscoreAccuracy);
EPBscoreF1all = mean(EPBscoreF1);
EPBscorePrecisionAll = mean(EPBscorePrecision);
EPBscoreTPRAll = mean(EPBscoreTPR);
F1all(ik) = mean(F1);
accuracyPerImage(ik) = mean(accuracy);
TPRPerImage(ik) = mean(TPR);
FPRPerImage(ik) = mean(FPR);
accuracyPerBouton(ik) = sum(TP) / (sum(numBoutons) + sum(FP) + sum(FN));
TPRPerBouton(ik) = sum(TP) / sum(numBoutons);
precisionAll(ik)= mean(precision);
disp(['iteration ', num2str(ik)])
ik = ik +1;
end
%% Plot ROC curve
figure;
plot(TPRPerImage, precisionAll, '-b', 'LineWidth',2 );
title('Precision-Recall Curve for bouton detection');
xlabel('Recall'); ylabel('Precision');
hold on;
axis([0,1,0,1]);
figure;
plot(FPRPerImage, TPRPerImage, '-r', 'LineWidth',2 );
title('ROC Curve for bouton detection');
xlabel('FPR'); ylabel('TPR');
hold on;
axis([0,0.00005,0,1]);
%% Save
%save('NewDataAnalysis-10k-2.mat', 'TPRPerImage', 'precisionAll', 'F1all', 'accuracyPerImage');
%save('NewDataAnalysis-barGraph.mat', 'TPR', 'precision', 'F1', 'EPBscoreTPR', 'EPBscorePrecision', 'EPBscoreF1')