-
Notifications
You must be signed in to change notification settings - Fork 0
/
warppos.m
29 lines (26 loc) · 909 Bytes
/
warppos.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
function warped = warppos(name, model, c, pos)
% warped = warppos(name, model, c, pos)
% Warp positive examples to fit model dimensions.
% Used for training root filters from positive bounding boxes.
ridx = model.components{c}.rootindex;
size = model.rootfilters{ridx}.size;
pixels = size * model.sbin;
heights = [pos(:).y2]' - [pos(:).y1]' + 1;
widths = [pos(:).x2]' - [pos(:).x1]' + 1;
numpos = length(pos);
warped = cell(numpos);
cropsize = (size+2) * model.sbin;
for i = 1:numpos
if mod(i,100)==0
fprintf('%s: warp: %d/%d\n', name, i, numpos);
end
im = color(imread(pos(i).im));
padx = model.sbin * widths(i) / pixels(2);
pady = model.sbin * heights(i) / pixels(1);
x1 = round(pos(i).x1-padx);
x2 = round(pos(i).x2+padx);
y1 = round(pos(i).y1-pady);
y2 = round(pos(i).y2+pady);
window = subarray(im, y1, y2, x1, x2, 1);
warped{i} = imresize(window, cropsize, 'bilinear');
end