forked from sentinel-hub/custom-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
54 lines (44 loc) · 983 Bytes
/
script.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
if (B8A == 0 || B11 == 0){
return [0,0,0];
} else {
var val = (B8A - B11)/(B8A + B11);
var vmin = -0.8;
var vmax = 0.8;
var dv = vmax - vmin;
var r = 0.0;
var g = 0.0;
var b = 0.0;
var v = val;
if (v < vmin){
v = vmin;
}
if (v > vmax){
v = vmax;
}
var l1 = 0.35;
var l2 = 0.48;
var l3 = 0.52;
var l4 = 0.65;
var level1 = (vmin + l1 * dv);
var level2 = (vmin + l2 * dv);
var level3 = (vmin + l3 * dv);
var level4 = (vmin + l4 * dv);
if (v < level1){
r = 0.5 + (v - vmin) / (level1 - vmin) / 2;
} else if (v < level2) {
r = 1;
g = (v - level1) / (level2 - level1);
b = 0;
} else if (v < level3) {
r = 1 + (level2 - v) / (level3 - level2);
g = 1;
b = (v - level2) / (level3 - level2);
} else if (v < level4) {
r = 0;
g = 1 + (level3 - v) / (level4 - level3);
b = 1;
} else {
b = 1.0 + (level4 - v) / (vmax - level4) / 2;
}
return [r, g, b];
}