forked from sergeyk/selective_search_ijcv_with_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlobAverageBestOverlap.m
73 lines (59 loc) · 2.55 KB
/
BlobAverageBestOverlap.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
function [abo mabo boScores avgNumSegments] = BlobAverageBestOverlap(gtBlobs, gtNrs, blobIndIm, blobBoxes, hierarchy, minWidth)
% [abo mabo boScores avgNumSegments] = BlobAverageBestOverlap(gtBlobs,
% gtNrs, blobIndIm, blobBoxes, hierarchy, minWidth)
%
% Calculate Average Best Overlap scores
%
% gtBlobs: Cell array of ground truth segments per class (see
% GetAllObjectBoxes)
% gtNrs: Cell array with image nrs corresponding to ground truth.
% blobIndIm: Image with indices per blob (mexFelzenSegmentIndex)
% blobBoxes: Boxes corresponding to blobs in blobIndIm
% hierarchy: Hierarchy necessary to reconstruct all blobs in grouping
% minWidth: (optional) Filter out blobs with a width smaller than minWidth.
%
% abo: Average Best Overlap per class (Pascal Overlap criterion)
% mabo: Mean Average Best Overlap (mean(abo))
% boScores: Best Overlap Score per GT segment.
% avgNumBlobs: Average number of blobs per image
%
% Jasper Uijlings - 2013
if ~exist('minWidth', 'var')
minWidth = 0;
end
nClasses = length(gtBlobs);
% Memory initialization
numSegments = zeros(length(blobIndIm), 1);
boScores = cell(1, nClasses);
for cI = 1:nClasses
boScores{cI} = length(gtBlobs{cI});
end
% indices per class
classIdx = ones(1, nClasses);
for cI=1:length(gtBlobs)
for i=1:length(gtBlobs{cI})
testImNr = gtNrs{cI}(i);
% the hierarchy here contains possibly multiple groupings with
% different initial measures
testBlobsT = cell(length(hierarchy{testImNr}), 1);
testBlobsT{1} = RecreateBlobHierarchyIndIm(blobIndIm{testImNr}, blobBoxes{testImNr}, hierarchy{testImNr}{1});
for j=2:length(hierarchy{testImNr}) % Without initial blobs here
[aa bb testBlobsT{j}] = RecreateBlobHierarchyIndIm(blobIndIm{testImNr}, blobBoxes{testImNr}, hierarchy{testImNr}{j});
end
testBlobs = cat(1, testBlobsT{:});
% Get rid of too small blobs
testBlobs = FilterBlobsWidth(testBlobs, minWidth);
numSegments(testImNr) = length(testBlobs);
% Calculate overlap scores
boScores{cI}(classIdx(cI)) = BlobBestOverlap(testBlobs, gtBlobs{cI}(i));
classIdx(cI) = classIdx(cI) + 1;
end
end
abo = zeros(nClasses, 1);
for cI = 1:nClasses
abo(cI) = mean(boScores{cI});
end
mabo = mean(abo);
% Average of numSegments. Make sure that only images for which the
% numSegments are actually calculated are taken into account.
avgNumSegments = mean(numSegments(numSegments > 0));