-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharp.js
82 lines (71 loc) · 2.05 KB
/
sharp.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var sharp = require('sharp')
var path = require('path')
var fs = require('fs')
var dirName = "./tmp/2013/228/EO1H0110282013228110T3_L1U_COMPOSITE_B26_B20_B12"
var redFileName = path.join(dirName, "EO1H0110282013228110T3_B026_L1U.TIF")
var greenFileName = path.join(dirName, "EO1H0110282013228110T3_B020_L1U.TIF")
var blueFileName = path.join(dirName, "EO1H0110282013228110T3_B012_L1U.TIF")
var outFileName = path.join(dirName, "EO1H0110282013228110T3_RGB_L1U.png")
var outFileName2 = path.join(dirName, "test.jpg")
var maskFileName = path.join(dirName, "mask.png")
console.log("Red", redFileName)
console.log("Making RGB...", outFileName)
try {
var alphaMask = sharp(redFileName)
.toColourspace('b-w')
.normalize()
// .greyscale()
// .negate()
.threshold(0)
.png()
.toBuffer()
// .toFile(maskFileName, function(err, info) {
// console.log("masked", err, info)
// })
// var redPromise = sharp(redFileName)
// .toColourspace('b-w')
// .extractChannel(1)
// .greyscale()
// .bandbool(sharp.bool.and)
// .png()
// .toBuffer()
var greenPromise = sharp(greenFileName)
.toColourspace('b-w')
.normalize()
// .greyscale()
.png()
.toBuffer()
var bluePromise = sharp(blueFileName)
.toColourspace('b-w')
.normalize()
// .greyscale()
.png()
.toBuffer()
Promise.all([alphaMask, greenPromise, bluePromise])
.then(function(results) {
console.log("All bands ready!", results.length)
sharp(redFileName)
// .toColourspace('b-w')
.normalize()
.greyscale()
.joinChannel([results[1], results[2], results[0]])
.toColourspace(sharp.colourspace.srgb)
.toFile(outFileName2, function(error, info) {
console.log("join err", error, info)
})
})
.catch( function(error) {
console.log("catch err", error)
})
//var greenimg = sharp(greenFileName)
//var blueimg = sharp(blueFileName)
//sharp()
//.toColorspace('sRGB')
//.joinChannel([redFileName, greenFileName, blueFileName])
//.png()
//.toFile(outFileName2, function(err, info) {
// console.log("toFile", err, info)
//})
} catch (e) {
console.log("Exception", e)
}