-
Notifications
You must be signed in to change notification settings - Fork 1
/
intersection_over_union.m
34 lines (23 loc) · 1.06 KB
/
intersection_over_union.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
function [ scalar ] = intersection_over_union( propose, groundtruth )
%UNTITLED calcuate the intersection-over-union(IoU) with given rectangle
%position
% Input: propose is the results from your algorithms and groundtruth is the
% groundtruth. They can be both specify one rectangle or matrices where
% each row is a position vector. And the num of rectangles of propose and
% groundtruth must be equal.
% Output: if inputs are just one rectangle's position, Area is a scalar.
% or if inputs are matrices, then Area is a vector and Area(i) is the
% intersection-over-union scalar of i-th rectangle.
if size(propose,1)~=size(groundtruth,1)
if size(groundtruth,1)<size(propose,1)
propose=propose(1:size(groundtruth,1),:);
end
end
rectintarea = rectint(propose, groundtruth);
rectintarea = diag(rectintarea);
propose_area = propose(:,3) .* propose(:,4);
groundtruth_area = groundtruth(:,3) .* groundtruth(:,4);
union_area = propose_area + groundtruth_area - rectintarea;
scalar = rectintarea ./ union_area;
scalar(find(union_area == 0)) = 0;
end