forked from xiaodongyang/SNV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSpatioTemporalGrids.m
46 lines (33 loc) · 951 Bytes
/
getSpatioTemporalGrids.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
function [ridx, cidx, fidx] = getSpatioTemporalGrids(bb, hist, scheme)
nrow = bb.rmax - bb.rmin + 1;
ncol = bb.cmax - bb.cmin + 1;
% row ranges of spatial grids
ridx = bb.rmin;
rstep = nrow / scheme.nrow;
for i = 1:(scheme.nrow - 1)
ridx = [ridx, bb.rmin + round(i * rstep)];
end
ridx = [ridx, bb.rmax];
% column ranges of spatial grids
cidx = bb.cmin;
cstep = ncol / scheme.ncol;
for i = 1:(scheme.ncol - 1)
cidx = [cidx, bb.cmin + round(i * cstep)];
end
cidx = [cidx, bb.cmax];
% frame ranges of adaptive temporal pyramids grids
fidx = cell(scheme.ntmp, 1);
% normalized accumulated motion energy
energy = cumsum(hist / sum(hist));
for i = 1:scheme.ntmp
nbins = 2 ^ (i - 1);
fstep = 1 / nbins;
buff = 1;
for j = 1:nbins
% index of the element that is the most closed to (j * fstep)
[~, frm] = min(abs(energy - j * fstep));
buff = [buff, frm];
end
fidx{i} = buff;
end
end