-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeKernelMatrixFromFlow.m
145 lines (117 loc) · 3.16 KB
/
makeKernelMatrixFromFlow.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function [K histogram]= makeKernelMatrixFromFlow(u, v)
%
[M, N] = size(u);
histogram = zeros(M*N, 1);
numFrame = 70;
% numFrame = 50;
% num_coeff = (1+2*numFrame*2);
num_coeff = (1+2*numFrame);
x_idx = zeros(M*N*num_coeff, 1);
y_idx = zeros(M*N*num_coeff, 1);
z_idx = zeros(M*N*num_coeff, 1);
one_over_num_frame = 1./(1+2*numFrame);
count = 1;
for j = 1:M
for i = 1:N
k = (j-1)*N + i;
for f = -numFrame:numFrame
jj = max(1, min(M, round(j + v(j, i)*f/numFrame)));
ii = max(1, min(N, round(i + u(j, i)*f/numFrame)));
kk = (jj - 1)*N + ii;
x_idx(count) = k;
y_idx(count) = kk;
z_idx(count) = one_over_num_frame*0.9;
count = count + 1;
% jj = max(1, min(M, jj + 1));
% ii = max(1, min(N, ii + 1));
% %
% %
% kk = (jj - 1)*N + ii;
% x_idx(count) = k;
% y_idx(count) = kk;
% z_idx(count) = one_over_num_frame*0.1;
% count = count + 1;
%
end
end
end
count = count - 1;
% K = sparse(x_idx(1:count), y_idx(1:count), z_idx(1:count), M*N, M*N);
K = sparse(x_idx(1:count), y_idx(1:count), 1./num_coeff, M*N, M*N);
% % K = sparse(y_idx(1:count), x_idx(1:count), z_idx, M*N, M*N);
%
%
% %
% [M, N] = size(u);
%
% numFrame = 75;%80;%100;
% one_over_num_frame = 1./numFrame;
%
% x_idx = zeros(M*N*(1+2*numFrame), 1);
% y_idx = zeros(M*N*(1+2*numFrame), 1);
% count = 1;
%
% for j = 1:M
% for i = 1:N
% k = (j-1)*N + i;
% for f = -numFrame:numFrame
% jj = round(j + v(j, i)*f*one_over_num_frame);
% ii = round(i + u(j, i)*f*one_over_num_frame);
% if 1 <= ii && ii <= N && 1 <= jj && jj <= M
% kk = (jj - 1)*N + ii;
% x_idx(count) = k; % from
% y_idx(count) = kk; % to
% count = count + 1;
% end
% end
% end
% end
% count = count - 1;
%
% K = sparse(y_idx(1:count), x_idx(1:count), 1/(1+2*numFrame), M*N, M*N);
%
%
%
% %
%
% [M, N] = size(u);
%
% numFrame = 70;%100;
% one_over_num_frame = 1./numFrame;
%
% x_idx = zeros(M*N*(1+2*numFrame), 1);
% y_idx = zeros(M*N*(1+2*numFrame), 1);
% z_idx = zeros(M*N*(1+2*numFrame), 1);
%
%
% histogram = zeros(M*N, 1);
% count = 1;
% for j = 1:M
% for i = 1:N
% k = (j-1)*N + i;
% for f = -numFrame:numFrame
% jj = round(j + v(j, i)*f*one_over_num_frame);
% ii = round(i + u(j, i)*f*one_over_num_frame);
% if 0 < ii && ii <= N && 0 < jj && jj <= M
% kk = (jj - 1)*N + ii;
% x_idx(count) = k; % from
% y_idx(count) = kk; % to
% histogram(kk) = histogram(kk) + 1;
% count = count + 1;
% end
% end
% end
% end
% count = count - 1;
% %
% K = sparse(y_idx(1:count), x_idx(1:count), 1/(1+2*numFrame), M*N, M*N);
%
%
%
% % for i = 1 : count
% % z_idx(i) = 1./histogram(y_idx(i));
% % end
%
% % for learning
% % K = sparse(y_idx(1:count), x_idx(1:count), z_idx(1:count), M*N, M*N);
%