forked from duanyueqi/CA-LBFL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdv_extract.m
65 lines (55 loc) · 1.97 KB
/
pdv_extract.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
function PDV =pdv_extract(data,M,N)
% Extract random PDV's at R=3 at different local regions
% Input:
% data: face images
% M: number of blocks in row level
% N: number of blocks in column level
%
% Output:
% PDV: Pixel Difference Vectors at R=3
% extract PDV samples from data
nn = [-3 -3; -2 -3; -1 -3; 0 -3; 1 -3; 2 -3; 3 -3; -3 -2; -2 -2; ...
-1 -2; 0 -2; 1 -2; 2 -2; 3 -2; -3 -1;-2 -1;-1 -1; 0 -1; 1 -1; ...
2 -1; 3 -1; -3 0; -2 0; -1 0; 1 0; 2 0; 3 0; -3 1; -2 1; -1 1; ...
0 1; 1 1; 2 1; 3 1; -3 2; -2 2;-1 2;0 2;1 2; 2 2; 3 2; -3 3; ...
-2 3; -1 3; 0 3; 1 3;2 3; 3 3];
R = 3;
randnum1 = min(16,floor((size(data,1)-R*2)/M));
randnum2 = min(16,floor((size(data,2)-R*2)/N));
PDV = cell(M, N);
for i=1:M
for j=1:N
PDV{i,j} = zeros(randnum1*randnum2*size(data,3),size(nn,1));
end
end
cnt = 0;
perm1 = randperm(floor((size(data,1)-R*2)/M));
perm2 = randperm(floor((size(data,2)-R*2)/N));
for d=1:size(data,3)
Tdata = double(data(:,:,d));
Tdata = preproc2(Tdata,0.2,1,2,[],[],10);
[h, w] = size(data(:,:,d));
CG = Tdata((R+1):(h-R), (R+1):(w-R));
Tcode1 = zeros(size(CG,1),size(CG,2),size(nn,1));
for ii=1:size(nn,1)
Tmp = Tdata(((R+1):(h-R))+nn(ii,1),((R+1):(w-R))+nn(ii,2));
Tcode1(:, :, ii) = Tmp-CG;
end
[Th, Tw, ~] = size(Tcode1);
delta_h = floor(Th / M);
delta_w = floor(Tw / N);
for i = 1:M
s_h = delta_h * (i-1) + 1;
e_h = s_h + delta_h - 1;
e_h = min(e_h, Th);
for j = 1:N
s_w = delta_w * (j-1) + 1;
e_w = s_w + delta_w - 1;
e_w = min(e_w, Tw);
Tmp = Tcode1(s_h:e_h, s_w:e_w, :);
PDV{i,j}(cnt+1:cnt+randnum1*randnum2,:) = ...
reshape(Tmp(perm1(1:randnum1),perm2(1:randnum2),:),randnum1*randnum2,size(nn,1));
end
end
cnt = cnt + randnum1*randnum2;
end