forked from ShaoqingRen/faster_rcnn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboxoverlap.m
40 lines (36 loc) · 1.26 KB
/
boxoverlap.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
function o = boxoverlap(a, b)
% Compute the symmetric intersection over union overlap between a set of
% bounding boxes in a and a single bounding box in b.
%
% a a matrix where each row specifies a bounding box
% b a matrix where each row specifies a bounding box
% AUTORIGHTS
% -------------------------------------------------------
% Copyright (C) 2011-2012 Ross Girshick
% Copyright (C) 2008, 2009, 2010 Pedro Felzenszwalb, Ross Girshick
%
% This file is part of the voc-releaseX code
% (http://people.cs.uchicago.edu/~rbg/latent/)
% and is available under the terms of an MIT-like license
% provided in COPYING. Please retain this notice and
% COPYING if you use this file (or a portion of it) in
% your project.
% -------------------------------------------------------
o = cell(1, size(b, 1));
for i = 1:size(b, 1)
x1 = max(a(:,1), b(i,1));
y1 = max(a(:,2), b(i,2));
x2 = min(a(:,3), b(i,3));
y2 = min(a(:,4), b(i,4));
w = x2-x1+1;
h = y2-y1+1;
inter = w.*h;
aarea = (a(:,3)-a(:,1)+1) .* (a(:,4)-a(:,2)+1);
barea = (b(i,3)-b(i,1)+1) * (b(i,4)-b(i,2)+1);
% intersection over union overlap
o{i} = inter ./ (aarea+barea-inter);
% set invalid entries to 0 overlap
o{i}(w <= 0) = 0;
o{i}(h <= 0) = 0;
end
o = cell2mat(o);