-
Notifications
You must be signed in to change notification settings - Fork 1
/
MinimizationOfEnergies.m
53 lines (44 loc) · 2.25 KB
/
MinimizationOfEnergies.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
% Minimizes the energy to inpaint the image "u_0" at pixels selected by "M".
% The minimization will stop once a convergence criterion defined by
% "tolerance" will be reached. "lambda" is used for similaity metrics,
% "half_patch_size" is the size of half a patch side (used to determine
% nearest-neighbors), and "median", "average" and "poisson" are mutually
% exclusive booleans determining which similarity metric to use. "sigma2"
% is the variance used for the Gaussian's creation in similarity metrics.
function [u, offset_map] = MinimizationOfEnergies(u_0, mask, sigma2, tolerance, lambda, half_patch_size, median, average, poisson)
cnt = 1;
u = u_0;
tmp_u_hat = padarray(u_0 .* ~mask, [half_patch_size, half_patch_size], -1);
tmp_mask = padarray(mask, [half_patch_size, half_patch_size], -1);
% Determining which error function will be used depending on the user's
% input.
if median == 1
error = 0;
elseif average == 1
error = 1;
else
error = 2;
end
% While norm(u_(k+1) - u_k) < tolerance
%while (norm(u(:) - u_0(:)) > tolerance || cnt == 1)
while cnt <= 10
disp(cnt);
u_1 = u; % Update of u_0 for the tolerance criterium.
% Correspondance update
if cnt == 1
offset_map = ParallelizedPatchMatch(u_1, u_1 .* ~mask, mask, half_patch_size, 1, error, lambda);%, lambda, M, sigma2, median, average, poisson,1);
else
offset_map = ParallelizedPatchMatch(u_1, u_1 .* ~mask, mask, half_patch_size, 1, error, lambda, offset_map);
end
% Confidence mask (used for image update)
decay_time = 5;
asymptotic_value = 5;
confidence_mask = ConfidenceMask(mask, decay_time, asymptotic_value);
% Image update
tmp_offset = padarray(offset_map, [half_patch_size, half_patch_size], -1);
u = ImageUpdate(tmp_offset, tmp_u_hat, tmp_mask, half_patch_size, sigma2, lambda, error);
% u = image_update(tmp_u_hat, tmp_offset, tmp_mask, lambda, confidence_mask, half_patch_size, sigma2);
% u = image_update_mean(tmp_u_hat, tmp_offset, tmp_mask, confidence_mask, half_patch_size, sigma2);
cnt = cnt + 1;
end
end