-
Notifications
You must be signed in to change notification settings - Fork 2
/
skeval.m
61 lines (53 loc) · 1.44 KB
/
skeval.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
function [best_f] = skeval( dets, gts, opts)
% evaluate skeleton detection precision and recall
% Input:
% dets: detections in cell
% gts: groundtruths in cell
% opts: options
if nargin < 3
opts.nthresh = 50;
opts.method = 'deepSK';
opts.score_path = 'scores';
end
assert(iscell(gts));
assert(iscell(dets));
assert(length(gts) == length(dets));
cntR_color = zeros(opts.nthresh,1);
sumR_color = zeros(opts.nthresh,1);
cntP_color = zeros(opts.nthresh,1);
sumP_color = zeros(opts.nthresh,1);
scores_color = zeros(length(gts),5);
for i=1:length(gts)
gt = gts{i}; det = dets{i};
assert(islogical(gt));
assert(sum(abs(size(gt) - size(det))) == 0); % check if size(gt)==size(det)
det = nms(det);
[cntR_color,sumR_color,cntP_color,sumP_color,scores_color, best_f] = ...
prScores(det,i ,gt,opts.nthresh,opts.method,...
cntR_color,sumR_color,cntP_color,sumP_color,scores_color,i,opts.score_path);
end
end
function [f] = fmeasure(r,p)
f = 2*p.*r./(p+r+((p+r)==0));
end
%% interpolate to find best F and coordinates thereof
function [bestT,bestR,bestP,bestF] = maxF(thresh,R,P)
bestT = thresh(1);
bestR = R(1);
bestP = P(1);
bestF = fmeasure(R(1),P(1));
for i = 2:numel(thresh),
for d = linspace(0,1),
t = thresh(i)*d + thresh(i-1)*(1-d);
r = R(i)*d + R(i-1)*(1-d);
p = P(i)*d + P(i-1)*(1-d);
f = fmeasure(r,p);
if f > bestF,
bestT = t;
bestR = r;
bestP = p;
bestF = f;
end
end
end
end