-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathsc_complete.m
94 lines (81 loc) · 2.9 KB
/
sc_complete.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
function imgCompleteFinal = sc_complete(imgFileName)
% SC_COMPLETE: image completion with user-defined mask
%
% Input:
% - imgFileName: image file name
% Output:
% - imgCompletion: completed result
%
% Example:
% imgFileName = '002_input_hole.png';
% imgCompletion = sc_complete(imgFileName);
%
% Disclaimer:
% This is a Matlab re-implementation of the paper:
%
% Jia-Bin Huang, Sing Bing Kang, Narendra Ahuja, and Johannes Kopf,
% Image Completion using Planar Structure Guidance,
% ACM Transactions on Graphics (Proceedings of SIGGRAPH 2014), 33(4), 2014
%
% It is provided for educational/researrch purpose only. If you find the
% software useful, please consider cite our paper.
%
% Contact:
% Jia-Bin Huang
% University of Illinois, Urbana-Champaign
% www.jiabinhuang.com
<<<<<<< HEAD
% Set up required path
startup;
% Load image
imgID = 9;
imgFileName = [num2str(imgID, '%03d'), '_input_hole.png'];
=======
% % Load image
% imgID = 3;
% imgFileName = [num2str(imgID, '%03d'), '_input_hole.png'];
>>>>>>> 80fe71bd858652004119dc8946439915385cc282
imgFileName = 'test.png';
% Option parameters
[optA, optS] = sc_init_opt;
% =========================================================================
% Planar structure extraction
% =========================================================================
fprintf('- Extract planar structures \n');
tic;
[img, mask, maskD, modelPlane, modelReg] = sc_extract_planar_structure(imgFileName, optA);
tAnalysis = toc;
fprintf('Done in %6.3f seconds.\n\n', tAnalysis);
% =========================================================================
% Guided image completion
% =========================================================================
% Construct image pyramid for coarse-to-fine image completion
fprintf('- Construct image pyramid: \n');
tic;
% Create image pyramid
[imgPyr, maskPyr, scaleImgPyr] = sc_create_pyramid(img, maskD, optS);
% Structure constraints
[modelPlane, modelReg] = sc_planar_structure_pyramid(scaleImgPyr, modelPlane, modelReg);
tImgPyramid = toc;
fprintf('Done in %6.3f seconds.\n\n', tImgPyramid);
% Completion by synthesis
fprintf('- Image completion using planar structure guidance \n');
tic;
imgPyr = sc_synthesis(imgPyr, maskPyr, modelPlane, modelReg, optS);
tSynthesis = toc;
fprintf('Synthesis took %6.3f seconds.\n', tSynthesis);
% Return the top level
imgSyn = imgPyr{optS.topLevel};
% =========================================================================
% Poisson blending
% =========================================================================
tic;
imgCompleteFinal = sc_poisson_blend(img, imgSyn, mask);
tBlend = toc;
fprintf('Blending took %6.3f seconds.\n', tBlend);
imwrite(imgCompleteFinal, fullfile('result', [imgFileName(1:end-4), '_completion.png']));
% [To-Do] Visualizing completion process
% sc_vis_synthesis_process(imgCompletePyr, imgPyrNNF, imgPyrCost);
end