-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathfastEllipseOverlap.m
95 lines (80 loc) · 2.71 KB
/
fastEllipseOverlap.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
function result = fastEllipseOverlap(f1, f2, varargin)
% FASTELLIPSEOVERLAP Compute overlaps of two sets ov ellipses
% EVAL = FASTELLIPSEOVERLAP(F1, F2) computes the overlap scores
% beteen all pairs of ellipses in F1 and F2. EVAL output structure
% of size(F2,2) contains following values:
%
% EVAL.NEIGH::
% The list of neighbours in F1 for each ellipse in F1.
%
% EVAL.SCORES::
% The correpsonding overlaps.
%
% When frame scale normalisation is not applied the function is
% symmetric. With rescaling, the frames of F2 are used to fix the
% scaling factors.
%
% MATCHELLIPSES(F1, F2, 'OptionName', OptionValue) accepts the
% following options:
%
% NormaliseFrames:: [true]
% Fix the the frames scale so that each F2 frame has got scale
% defined by the 'NormalisedScale' option value.
%
% NormalisedScale:: [30]
% When frames scale normalisation applied, fixed scale of frames
% in F2.
%
% MinAreaRatio:: [0.3]
% Precise ellipse overlap is calculated only for ellipses E1
% and E2 which area ratio is bigger than 'minAreaRatio', s.t.:
%
% area(E1)/area(E2) > minAreaRatio, area(E1) < area(E2)
% Authors: Andrea Vedaldi, Karel Lenc
% AUTORIGHTS
import benchmarks.*;
conf.normaliseFrames = true ;
conf.normalisedScale = 30 ;
conf.minAreaRatio = 0.5;
% conf = helpers.vl_argparse(conf, varargin) ;
% eigenvalues (radii squared)
[e1,eigVec1] = helpers.ellipseEigen(f1) ;
[e2,eigVec2] = helpers.ellipseEigen(f2) ;
vggEll1 = helpers.ellToVgg(f1,e1,eigVec1);
vggEll2 = helpers.ellToVgg(f2,e2,eigVec2);
% areas
a1 = pi * sqrt(prod(e1,1)) ;
a2 = pi * sqrt(prod(e2,1)) ;
N2 = size(f2,2) ;
neighs = cell(1,N2) ;
scores = cell(1,N2) ;
if isempty(f1) || isempty(f2)
result.neighs = neighs ;
result.scores = scores ;
return;
end
% Given two ellipses f1, f2, we want to upper bound their overlap
% (inters over union). We have
%
% overlap(f1,f2) = |inters(f1,f2)| / |union(f1,f2)| <= maxOverlap
% maxOverlap = min(|f1|,|f2|) / max(|f1|,|f2|)
%
%
for i2 = 1:N2
s = conf.normalisedScale / sqrt(a2(i2) / pi) ;
canOverlap = sqrt(vl_alldist2(f2(1:2, i2), f1(1:2,:))) < 4 * sqrt(a2(i2) / pi);
maxOverlap = min(a2(i2), a1) ./ max(a2(i2), a1) .* canOverlap ;
neighs{i2} = find(maxOverlap > conf.minAreaRatio) ;
if conf.normaliseFrames
vggS = [1 1 1/s^2 1/s^2 1/s^2 s s s s]';
lhsEllipse = vggS.*vggEll2(:,i2);
rhsEllipse = bsxfun(@times,vggEll1(:,neighs{i2}),vggS);
else
lhsEllipse = vggEll2(:,i2);
rhsEllipse = vggEll1(:,neighs{i2});
end
scores{i2} = helpers.computeEllipseOverlap(lhsEllipse,rhsEllipse)';
end
result.neighs = neighs;
result.scores = scores;
end