-
Notifications
You must be signed in to change notification settings - Fork 19
/
ospa_dist.m
72 lines (57 loc) · 1.86 KB
/
ospa_dist.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
%This code is available online at http://ba-ngu.vo-au.com/vo/OSPA_for_Tracks.zip
function [dist varargout]= ospa_dist(X,Y,c,p)
%
%B. Vo. 26/08/2007
%Compute Schumacher distance between two finite sets X and Y
%as described in the reference
%[1] D. Schuhmacher, B.-T. Vo, and B.-N. Vo, "A consistent metric for performance evaluation in multi-object
%filtering," IEEE Trans. Signal Processing, Vol. 56, No. 8 Part 1, pp. 3447– 3457, 2008.
%
%Inputs: X,Y- matrices of column vectors
% c - cut-off parameter (see [1] for details)
% p - p-parameter for the metric (see [1] for details)
%Output: scalar distance between X and Y
%Note: the Euclidean 2-norm is used as the "base" distance on the region
%
if nargout ~=1 & nargout ~=3
error('Incorrect number of outputs');
end
if isempty(X) & isempty(Y)
dist = 0;
if nargout == 3
varargout(1)= {0};
varargout(2)= {0};
end
return;
end
if isempty(X) | isempty(Y)
dist = c;
if nargout == 3
varargout(1)= {0};
varargout(2)= {c};
end
return;
end
%Calculate sizes of the input point patterns
n = size(X,2);
m = size(Y,2);
%Calculate cost/weight matrix for pairings - fast method with vectorization
XX= repmat(X,[1 m]);
YY= reshape(repmat(Y,[n 1]),[size(Y,1) n*m]);
D = reshape(sqrt(sum((XX-YY).^2)),[n m]);
D = min(c,D).^p;
% %Calculate cost/weight matrix for pairings - slow method with for loop
% D= zeros(n,m);
% for j=1:m
% D(:,j)= sqrt(sum( ( repmat(Y(:,j),[1 n])- X ).^2 )');
% end
% D= min(c,D).^p;
%Compute optimal assignment and cost using the Hungarian algorithm
[assignment,cost]= Hungarian(D);
%Calculate final distance
dist= ( 1/max(m,n)*( c^p*abs(m-n)+ cost ) ) ^(1/p);
%Output components if called for in varargout
if nargout == 3
varargout(1)= {(1/max(m,n)*cost)^(1/p)};
varargout(2)= {(1/max(m,n)*c^p*abs(m-n))^(1/p)};
end