-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.js
61 lines (56 loc) · 2.11 KB
/
example.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const Pxlsrt = require('../dist/pxlsrt.js');
const path = require('path');
const paths = {
wall: path.join(__dirname, './wall.png'),
court: path.join(__dirname, './court.jpg'),
kat: path.join(__dirname, './kat.png'),
output: function(number) {
return path.join(__dirname, 'sort.' + number + '.png');
},
};
// Load local image and sort with brute sorting filter
Pxlsrt.read(paths.wall).then(function(image) {
console.log('Loaded ' + paths.wall);
let output = paths.output(1);
image.filter('brute', {
min: 200, // Minimum band size of 200
max: 200, // Maximum band size of 200
method: 'hue', // Sort by hue
direction: 'vertical', // Sort vertically.
middlate: 1, // Radiate from middle of band
}).write(output);
console.log('Saved to ' + output);
});
// Load local image and sort with smart sorting filter
Pxlsrt.read(paths.kat).then(function(image) {
console.log('Loaded ' + paths.kat);
let output = paths.output(2);
image.filter('smart', {
threshold: 100, // Increase pixel collection threshold for grainy, complex photo
method: 'none', // Don't actually sort
reverse: true, // Reverse bands
}).write(output);
console.log('Saved to ' + output);
});
// Chain brute sort to sort across all directions
Pxlsrt.read(paths.court).then(function(image) {
console.log('Loaded ' + paths.court);
let output = paths.output(3);
image.filter('brute', {direction: 'horizontal'}) // Sort horizontally
.filter('brute', {direction: 'tlbr'}) // Sort top-left to bottom-right diagonal
.filter('brute', {direction: 'vertical'}) // Sort vertically
.filter('brute', {direction: 'trbl'}) // Sort top-right to bottom-left diagonal
.filter('brute', {direction: 'horizontal'}) // Sort horizontally
.write(output);
console.log('Saved to ' + output);
});
// Smoothly sort
Pxlsrt.read(paths.kat).then(function(image) {
console.log('Loaded ' + paths.kat);
let output = paths.output(4);
image.filter('brute', {
method: 'cyan', // Sort by cyan value
smooth: true, // Group same pixels together when sorting
}).write(output);
console.log('Saved to ' + output);
});