-
Notifications
You must be signed in to change notification settings - Fork 1
/
best_coherence_match.asv
95 lines (74 loc) · 2.21 KB
/
best_coherence_match.asv
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
function [ best_coh_i, best_coh_j] = best_coherence_match( A_pyramid, A_prime_pyramid, ...
B_pyramid, B_prime_pyramid, s_pyramid, l, L, i, j)
%BEST_COHERENCE_MATCH
global N_BIG;
% global N_SMALL;
[A_h, A_w, ~] = size(A_pyramid{1});
% (i,j) are q in the paper
border_big = floor(N_BIG/2);
% border_small = floor(N_SMALL/2);
F_q = concat_feature(B_pyramid, B_prime_pyramid, ...
l, i, j, L);
min_dist = inf;
r_star_i = -1;
r_star_j = -1;
%loop over image
done = false;
for ii = i-border_big:i+border_big
for jj = j-border_big:j+border_big
% Done, (i,j) is the first un-synthesized pixel
if ii == i && jj == j
done = true;
break
end
fprintf('~~~~~~~~~~~~~~~~~~\n')
% [s_i, s_j] = s_pyramid{l}(ii,jj,:);
% size(s_pyramid{l})
s_i = s_pyramid{l}(ii,jj,1);
s_j = s_pyramid{l}(ii,jj,2);
% s_i
% s_j
% i - ii
% j - jj
fprintf('q: (%d, %d), q-r: (%d, %d)\n', i, j, i-ii, j-jj);
fprintf('r: (%d, %d)\n', ii, jj);
fprintf('s(r): (%d, %d)\n', s_i, s_j);
F_sr_i = s_i + (i - ii); % this is a problem for when s is not yet
F_sr_j = s_j + (j - jj); % set, we solve this by just doing
% approx match only for first 3 rows.
if F_sr_i > A_h || F_sr_i < 1 || F_sr_j > A_w || F_sr_j
% F_sr_i
% F_sr_j
fprintf('s(r) + (q-r): (%d, %d)\n', F_sr_i, F_sr_j);
F_sr = concat_feature(A_pyramid, A_prime_pyramid, l, ...
F_sr_i, F_sr_j, L);
fprintf('sum(F_sr(:)) %d \n', sum(F_sr(:)));
dist = sum((F_sr(:) - F_q(:)).^2);
if dist < min_dist
min_dist = dist;
r_star_i = ii;
r_star_j = jj;
end
end
if done
break
end
end
% Now set best pixel to return
s_rstar_i = s_pyramid{l}(r_star_i,r_star_j,1);
s_rstar_j = s_pyramid{l}(r_star_i,r_star_j,2);
fprintf('===\n');
fprintf('r*: (%d, %d), q-r*: (%d, %d)\n', ...
r_star_i, r_star_j, (i - r_star_i), (j - r_star_j));
fprintf('s(r*): (%d, %d)\n', s_rstar_i, s_rstar_j);
fprintf('p: (%d, %d)\n', s_rstar_i + (i - r_star_i), ...
s_rstar_j + (j - r_star_j));
% r_star_i
% r_star_j
% (i - r_star_i)
% (j - r_star_j)
% s_rstar_i
% s_rstar_j
best_coh_i = s_rstar_i + (i - r_star_i);
best_coh_j = s_rstar_j + (j - r_star_j);
end