forked from xiaodongyang/SNV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoolOneTemporalLevel.m
82 lines (65 loc) · 2.63 KB
/
poolOneTemporalLevel.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
74
75
76
77
78
79
80
81
82
function desc = poolOneTemporalLevel(scheme, pns, locs, basis, codes, ridx, cidx, fidx, ntmps)
% descriptor dimension of each spatio-temporal grid
ndims = scheme.ncenters * size(pns, 2);
% initialize
desc = zeros(1, (scheme.nrow * scheme.ncol) * ntmps * ndims);
s = 1; e = 0;
for i = 1:ntmps
for j = 1:scheme.nrow
for k = 1:scheme.ncol
% polynormal index of one spatio-temporal grid
stidx = (locs.frms >= fidx(i)) & (locs.frms <= fidx(i + 1)) & ...
(locs.rows >= ridx(j)) & (locs.rows <= ridx(j + 1)) & ...
(locs.cols >= cidx(k)) & (locs.cols <= cidx(k + 1));
% if this grid contains all-zero polynormals
if sum(stidx) == 0
e = e + ndims;
s = e + 1;
continue;
end
% polynormals, codes, and frames of one spatio-temporal grid
stpns = pns(stidx, :);
stcodes = codes(stidx, :);
stfrms = locs.frms(stidx);
count = 1;
nfrms = length(unique(stfrms));
feats = zeros(nfrms, ndims);
for f = fidx(i):fidx(i + 1)
if sum(stfrms == f) == 0
continue;
end
% polynormals and codes of one frame
tpns = stpns(stfrms == f, :);
tcodes = stcodes(stfrms == f, :);
for c = 1:scheme.ncenters
% coefficient-weighted difference
buff = tpns - repmat(basis(c, :), size(tpns, 1), 1);
buff = buff .* repmat(tcodes(:, c), 1, size(tpns, 2));
buff = sum(buff);
% spatial averaging
reg = (ridx(j + 1) - ridx(j) + 1) * (cidx(k + 1) - cidx(k) + 1);
buff = buff / reg;
scol = (c - 1) * size(tpns, 2) + 1;
ecol = c * size(tpns, 2);
feats(count, scol:ecol) = buff;
end
count = count + 1;
end
% remove rows corresponding to all-zero polynormal frames
if count < nfrms
feats(count:end, :) = [];
end
% temporal max pooling
if nfrms > 1
adesc = max(feats);
else
adesc = feats;
end
% concatenation
e = e + ndims;
desc(s:e) = adesc;
s = e + 1;
end
end
end
end