-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_tau.m
115 lines (78 loc) · 3.21 KB
/
init_tau.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
clear;
close all;
addpath(genpath('TV_L1_OF'));
img_dirs = ['C:\Papers\Video deblurring\video_deblur_dataset\bridge\input\'];
flow_dirs = ['C:\Papers\Video deblurring\video_deblur_dataset\bridge\flow\'];
imlist = dir([img_dirs '*.jpg']);
n_imlist = length(imlist)
% flow_forward = cell(n_imlist, 1);
% flow_backward = cell(n_imlist, 1);
% for i = 1 : n_imlist
i = 82;
flow_forward_name = [flow_dirs sprintf('%04dTo%04d.flo', i, i+1)];
flow_backward_name = [flow_dirs sprintf('%04dTo%04d.flo', i, i-1)];
flow_forward = readFlowFile(flow_forward_name);
flow_backward = readFlowFile(flow_backward_name);
[M N C] = size(flow_backward)
kernel = double(imread('kernel.png'));
% neg_dix = kernel < 0.05*max(kernel(:));
% kernel(neg_dix) = 0;
kernel = kernel./sum(kernel(:));
[kernel_size, ~] = size(kernel);
num_samples = 25;
one_over_num_samples = 1./num_samples;
one_over_1plus_2_times_num_samples = 1./(2*num_samples + 1);
kernel_default = zeros(kernel_size, kernel_size);
half_kernel_size = ceil(kernel_size/2);
kernel_default(half_kernel_size, half_kernel_size) = one_over_1plus_2_times_num_samples;
% tau = 0.5
for tau = 0.05 : 0.005: 0.5
% tau = 1
kernel_sum = zeros(kernel_size, kernel_size);
% for i = 421 : 5 : 620 %bicycle
% for j = 161 : 5 : 360
for i = 181 : 5 : 380 % car
for j = 421 : 5 : 620
kernel = kernel_default;
for s = 1 : num_samples
u = tau*flow_backward(i, j, 1)*s*one_over_num_samples;
v = tau*flow_backward(i, j, 2)*s*one_over_num_samples;
u = max(1, min(kernel_size, round(half_kernel_size + u)));
v = max(1, min(kernel_size, round(half_kernel_size + v)));
kernel(u, v) = kernel(u, v) + one_over_1plus_2_times_num_samples;
u = tau*flow_forward(i, j, 1)*s*one_over_num_samples;
v = tau*flow_forward(i, j, 2)*s*one_over_num_samples;
u = max(1, min(kernel_size, round(half_kernel_size + u)));
v = max(1, min(kernel_size, round(half_kernel_size + v)));
kernel(u, v) = kernel(u, v) + one_over_1plus_2_times_num_samples;
end
%
kernel_sum = kernel_sum + kernel;
end
end
g = fspecial('gaussian', [3 3], 0.3);
kernel_sum = imfilter(kernel_sum, g, 'same');
max_kernel = max(kernel_sum(:));
neg_idx = 0.05*max_kernel > max_kernel;
kernel_sum(neg_idx) = 0;
kernel_sum = kernel_sum./sum(kernel_sum(:));
dist = abs(kernel_sum - kernel);
dist = dist.*dist;
ham_dist = 0;
for kx = 1 : kernel_size
for ky = 1 : kernel_size
if kernel(ky, kx) > 0 && kernel_sum(ky, kx) > 0
elseif kernel(ky, kx) == 0 && kernel_sum(ky, kx) == 0
else
ham_dist = ham_dist + 1;
end
end
end
kernel_sum = 255*kernel_sum./max(kernel(:));
imwrite(kernel_sum, 'kernel_sum.png')
drawnow;
fprintf('tau:%f, dist:%f ham_dist:%f\n', tau, sum(dist(:)), ham_dist);
% pause
end
%
%