forked from ivaaanrm/PIV-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo7.m
64 lines (46 loc) · 1.13 KB
/
algo7.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
clear all
files = dir(['Fingers_knn_single/', '/*.txt']);
preds_ = [];
refs_ = [];
aciertos = 0;
for i = 1 : length(files)
% path de las máscaras
imgName = files(i).name;
% valor de referencia
ref = strsplit(imgName, '_');
ref = str2num(['uint8(',ref{1},')']);
% Leer el numero
path = "Fingers_knn_single/"+imgName;
fileID = fopen(path,'r');
formatSpec = '%d';
pred = fscanf(fileID,formatSpec);
fclose(fileID);
preds_ = vertcat(preds_,pred);
refs_ = vertcat(refs_, ref);
if pred == ref
aciertos = aciertos + 1;
else
image = strsplit(imgName,'.');
name = "fingers_masks_val/"+ image(1) +".bmp";
figure
imshow(imread(name))
title(pred)
end
end
%% Results
% Accuracy
accuracy = aciertos/length(refs_);
accuracy
% cm = confusionmat(uint8(preds_),uint8(refs_));
% tp = cm(2,2);
% tn = cm(1,1);
% fn = cm(1,2);
% fp = cm(2,1);
%
% precision = tp/(tp+fp);
% recall = tp/(tp+fn);
% Calculo del F1 Score total
% precision = tp/(tp+fp);
% recall = tp/(tp+fn);
% F1score_total = (2*precision*recall)/(precision+recall);
% F1score_total