-
Notifications
You must be signed in to change notification settings - Fork 28
/
whitening_norm.m
69 lines (62 loc) · 1.78 KB
/
whitening_norm.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
% ZCA & l1-norm operation
function output = whitening_norm(features)
features = im2double(features);
% output = features;
output = zca(features);
output = l1_norm(output);
% output = l2_norm(output);
% output = nuclear(output);
end
% l1-norm
function output = l1_norm(features)
[h,w,c] = size(features);
output = zeros(h, w);
unit = 5;
% padding
pad = (unit-1)/2;
feature_temp = zeros(h+unit-1, w+unit-1, c);
feature_temp(1+pad:h+pad, 1+pad:w+pad, :) = features;
for i=1+pad:h+pad
for j=1+pad:w+pad
temp = feature_temp(i-pad:i+pad, j-pad:j+pad, :);
norm = sum(sum(sum(abs(temp),3)))/(unit*unit);
output(i-pad, j-pad) = norm;
end
end
end
% l2-norm
function output = l2_norm(features)
[h,w,c] = size(features);
output = zeros(h, w);
unit = 5;
% padding
pad = (unit-1)/2;
feature_temp = zeros(h+unit-1, w+unit-1, c);
feature_temp(1+pad:h+pad, 1+pad:w+pad, :) = features;
for i=1+pad:h+pad
for j=1+pad:w+pad
temp = feature_temp(i-pad:i+pad, j-pad:j+pad, :);
temp = temp.*temp;
norm = sum(sum(sqrt(sum(temp,3))))/(unit*unit);
output(i-pad, j-pad) = norm;
end
end
end
% nuclear-norm
function output = nuclear(features)
[h,w,c] = size(features);
output = zeros(h, w);
unit = 5;
% padding
pad = (unit-1)/2;
feature_temp = zeros(h+unit-1, w+unit-1, c);
feature_temp(1+pad:h+pad, 1+pad:w+pad, :) = features;
for i=1+pad:h+pad
for j=1+pad:w+pad
temp = reshape(feature_temp(i-pad:i+pad, j-pad:j+pad, :), [unit*unit c]);
[U, S, V] = svd(temp, 'econ');
nu_norm = sum(diag(S));
output(i-pad, j-pad) = nu_norm;
end
end
end