-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathinpaint.js
More file actions
121 lines (117 loc) · 3.53 KB
/
inpaint.js
File metadata and controls
121 lines (117 loc) · 3.53 KB
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
"use strict";
var parse_args = require('./commargs.js'),
fs = require('fs'),
F = require('./filterwithcanvas.js'),
parallel = !!parse_args().options['parallel'];
function process(target, markup, source, output, params)
{
const inpainter = F.PatchMatchFilter();
console.log('Inpainting runs "' + (parallel ? 'parallel' : 'synchronous') + '"');
if (parallel) inpainter.worker(true);
console.log('Loading images..');
F.Image.load(target, function(img) {
F.Image.load(markup, function(mkup) {
function inpaint(toSelection, fromSelection, fromInput)
{
console.log('Inpainting image..')
if (fromInput) inpainter.setInput("input", fromInput);
params = params || {};
params.fromSelection = {points:fromSelection.points(), data:fromInput?"input":null};
params.toSelection = {points:toSelection.points()};
inpainter.params(params).apply(img, function () {
console.log('Inpainting completed', inpainter.meta.metric.delta, inpainter.meta.metric.error);
if (parallel) inpainter.worker(false);
img.oCanvas.toPNG().then(function(png) {
fs.writeFile(output, png, function(err) {
if (err) console.log('error while saving image: ' + err.toString());
else console.log('Inpainted image saved');
})
}).catch(function(err) {
console.log('error while exporting image: ' + err.toString());
});
});
}
// eg remove part/complete image
const removeSelection = new F.Util.Image.Selection(mkup.getData(), img.width, img.height, 4);
if (source)
{
F.Image.load(source, function(src) {
inpaint(removeSelection, new F.Util.Image.Selection(src.getData(), img.width, img.height, 4), src);
});
}
else
{
inpaint(removeSelection, removeSelection.complement());
}
});
});
}
const run = 0, notrun = 1;
notrun || process(
__dirname+'/che.jpg',
__dirname+'/che_mask.png',
__dirname+'/che_donor.png',
__dirname+'/che_inpainted.png',
{
patch: 29,
iterations: 5,
alpha: 0.5,
radius: 20,
threshold: 1/(255*255),
delta: 1/400,
epsilon: 0,
ignore_excluded: false,
with_gradients: false,
with_distance_transform: false,
kernel: 0,
bidirectional: false,
reconstruct: ["average", "best"],
repeat: 5,
multiscale: true,
layered: true
}
);
notrun || process(
__dirname+'/t067.jpg',
__dirname+'/m067.png',
null,
__dirname+'/r067.png',
{
patch: 11,
iterations: 10,
alpha: 0.5,
radius: 50,
threshold: 1/(255*255),
delta: 1/100,
epsilon: 0,
with_gradients: true,
with_texture: true,
bidirectional: false,
reconstruct: ["average", "best"],
repeat: 10,
multiscale: true,
layered: true
}
);
run || process(
__dirname+'/t009.jpg',
__dirname+'/m009.png',
null,
__dirname+'/r009.png',
{
patch: 21,
iterations: 10,
alpha: 0.5,
radius: 200,
threshold: 1/(255*255),
delta: 1/400,
epsilon: 0,
with_gradients: true,
with_texture: true,
bidirectional: false,
reconstruct: ["average", "best"],
repeat: 10,
multiscale: true,
layered: true
}
);