-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathcomplete_image.js
42 lines (39 loc) · 1.74 KB
/
complete_image.js
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
"use strict";
var parse_args = require('./commargs.js'),
fs = require('fs'),
F = require('./filterwithcanvas.js'),
parallel = !!parse_args().options['parallel'],
completer = F.PatchMatchFilter(),
image = __dirname+'/t067.jpg',
markup = __dirname+'/m067.png',
output = __dirname+'/t067_completed.png';
console.log('Editing runs "' + (parallel ? 'parallel' : 'synchronous') + '"');
if (parallel) completer.worker(true);
console.log('Loading images..');
F.Image.load(image, function(img) {
F.Image.load(markup, function(part_to_remove) {
const removeArea = new F.Util.Image.Selection(part_to_remove.getData(), img.width, img.height, 4, {x:0, y:0, width:img.width, height:img.height});
const fromArea = removeArea.complement();
console.log('Completing image..')
completer.params({
patch: 51,
radius: 20,
pyramid: {iterations:5, changedThreshold:0.02, diffThreshold:0.09},
op: "resolve",
strict: true,
fromArea: {x:0, y:0, width:img.width, height:img.height, points:fromArea.points()},
toArea: {x:0, y:0, width:img.width, height:img.height, points:removeArea.points()}
}).apply(img, function () {
console.log('Editing completed');
if (parallel) completer.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('edited image saved');
})
}).catch(function(err) {
console.log('error while saving image: ' + err.toString());
});
});
});
});