-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_relaibitlity.m
58 lines (46 loc) · 2.45 KB
/
compute_relaibitlity.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
function [overlaps,distances] = ...
compute_relaibitlity(positions, ground_truth)
% [distance_precision, PASCAL_precision, average_center_location_error] = ...
% compute_performance_measures(positions, ground_truth, distance_precision_threshold, PASCAL_threshold)
%
% For the given tracker output positions and ground truth it computes the:
% * Distance Precision at the specified threshold (20 pixels as default if
% omitted)
% * PASCAL Precision at the specified threshold (0.5 as default if omitted)
% * Average Center Location error (CLE).
%
% The tracker positions and ground truth must be Nx4-matrices where N is
% the number of time steps in the tracking. Each row has to be on the form
% [c1, c2, s1, s2] where (c1, c2) is the center coordinate and s1 and s2
% are the size in the first and second dimension respectively (the order of
% x and y does not matter here).
if size(positions,1) ~= size(ground_truth,1),
disp('Could not calculate precisions, because the number of ground')
disp('truth frames does not match the number of tracked frames.')
return
end
ground_truth = [ground_truth(:,1:2) + (ground_truth(:,3:4) - 1) / 2 , ground_truth(:,3:4)];
positions = [positions(:,1:2) + (positions(:,3:4) - 1) / 2 , positions(:,3:4)];
%calculate distances to ground truth over all frames
distances = sqrt((positions(:,1) - ground_truth(:,1)).^2 + ...
(positions(:,2) - ground_truth(:,2)).^2);
distances(isnan(distances)) =Inf;
%calculate distance precision
%calculate average center location error (CLE)
%calculate the overlap in each dimension
overlap_height = min(positions(:,1) + positions(:,3)/2, ground_truth(:,1) + ground_truth(:,3)/2) ...
- max(positions(:,1) - positions(:,3)/2, ground_truth(:,1) - ground_truth(:,3)/2);
overlap_width = min(positions(:,2) + positions(:,4)/2, ground_truth(:,2) + ground_truth(:,4)/2) ...
- max(positions(:,2) - positions(:,4)/2, ground_truth(:,2) - ground_truth(:,4)/2);
% if no overlap, set to zero
overlap_height(overlap_height < 0) = 0;
overlap_width(overlap_width < 0) = 0;
% remove NaN values (should not exist any)
valid_ind = ~isnan(overlap_height) & ~isnan(overlap_width);
% calculate area
overlap_area = overlap_height(valid_ind) .* overlap_width(valid_ind);
tracked_area = positions(valid_ind,3) .* positions(valid_ind,4);
ground_truth_area = ground_truth(valid_ind,3) .* ground_truth(valid_ind,4);
% calculate PASCAL overlaps
overlaps = overlap_area ./ (tracked_area + ground_truth_area - overlap_area+eps);
end