-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDCTNet_FilterBank.m
49 lines (42 loc) · 1.32 KB
/
DCTNet_FilterBank.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
% Author : Cong Jie, Ng
% Paper : Ng, C. J., and Teoh, A. B. J. "DCTNet: A Simple Learning-Free Approach for Face Recognition." In 2015 Asia-Pacific Signal and Information Processing Association Annual Summit and Conference (APSIPA), 761-68, 2015.
function dctFilters = DCTNet_FilterBank(Params)
dctFilters = cell(Params.NumLayers, 1);
for i = 1:Params.NumLayers
ps = Params.FilterSize(i);
nf = Params.NumFilters(i);
dctMatrix = DCT_Matrix(ps);
diagIndex = AntiDiagonal_Index(ps, 1);
dctMatrix(:, diagIndex) = dctMatrix(:,:);
dctFilters{i} = dctMatrix(:, 2:nf+1);
end
end
function dctMatrix = DCT_Matrix(N)
dctMat = dctmtx(N);
dctMatrix = zeros(N * N, N * N);
for i = 1:N
for j = 1:N
M = dctMat(i,:)' * dctMat(j,:);
dctMatrix(:, (i-1) * N + j) = M(:);
end
end
end
function indices = AntiDiagonal_Index(n, direction)
% direction = 1 => north east
% direction = 0 => south west
indices = zeros(n, n);
idx = 1;
for i = 1:n
u = i; v = 1;
while u
indices(u, v) = idx;
indices(n - u + 1, n - v + 1) = n*n - idx + 1;
idx = idx + 1;
u = u - 1;
v = v + 1;
end
end
if direction
indices = indices';
end
end