-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelabelpos.m~
72 lines (63 loc) · 2.31 KB
/
relabelpos.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
function [newPos] = relabelpos(pos, model)
% Relabel positive examples given a trained root filter
filt_px_width=model.sbin*model.maxsize(2);
filt_px_height=model.sbin*model.maxsize(1);
newPos = pos;
for i=1:size(pos,2)
% Existing bounding box and image size
trueBbox = [pos(1,i).x1, pos(1.i).y1, pos(1,i).x2, pos(1,i).y2];
bbox_width=pos(1,i).x2-pos(1,i).x1;
bbox_height=pos(1,i).y2-pos(1,i).y1;
image=imread(pos(1,i).im);
image_size=size(image);
% pad the existing bounding box
padx=0.3*min(bbox_width,filt_px_width);
pady=0.3*min(bbox_height,filt_px_height);
% Compute range over which the root filter latent position is searched
new_x1=max(1,pos(1,i).x1-padx);
new_x2=min(image_size(2),pos(1,i).x2+padx);
new_y1=max(1,pos(1,i).y1-pady);
new_y2=min(image_size(1),pos(1,i).y2+pady);
% Construct the padded image and clear the original image
testim=image(new_y1:new_y2,new_x1:new_x2,:);
clear image;
% Compute Score
[scores,scales,padx_feature,pady_feature]=computeScores(testim,model,false);
maxScore = -realmax;
maxBbox = [-1, -1, -1, -1];
for c=1:model.numcomponents
scorePyramid = scores{c};
rsize = model.rootfilters{model.components{c}.rootindex}.size;
for level=1:length(scorePyramid)
score = scorePyramid{level};
scale = scales(l);
x = -1;
y = -1;
while true
[maxCols, ys] = max(score);
[maxVal, xs] = max(maxCols);
if (maxVal <= maxScore)
break;
end
x = xs;
y = ys(x);
predictedBbox = getBoundingBox(x, y, scale, padx_feature, pady_feature, rsize);
overlap = computeOverlap(predictedBbox, trueBbox);
if overlap < 0.7
score(y, x) = -realmax;
x = -1;
y = -1;
else
maxScore = maxVal;
maxBbox = predictedBbox;
break;
end
end
end
end
newPos(1, i).x1 = maxBbox(1);
newPos(1, i).y1 = maxBbox(2);
newPos(1, i).x2 = maxBbox(3);
newPos(1, i).y2 = maxBbox(4);
end
end