forked from sentinel-hub/custom-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (43 loc) · 1.65 KB
/
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
// 1- definition of math functions
var abs = Math.abs;
var ceiling = Math.ceil;
var cos = Math.cos;
var exp = Math.exp;
var floor = Math.floor;
var log = Math.log;
var sin = Math.sin;
var sqrt = Math.sqrt;
var truncate = Math.trunc;
var round=Math.round;
// 2- definition of output colors for representation of pixels (can be modified)
var WHITE= [1,1,1];
var BLACK = [0.0, 0.0, 0.0];
var RGB = [2.5*B04,2.5*B03,2.5*B02]
var custom = [2.5*B03,2.5*B04,2.5*B02]; //this one can be modified according to user's wish
// 3- actual representation of the two classes (can be changed according to user wish)
var cloud = WHITE;
var no_cloud = RGB;
// 4- formulas generated by the algorithm
// formula for first class
function output_first(band4, band7, band1)
{
return 2.16246741593412 - 0.796409165054949*band4 + 0.971776520302587*sqrt(abs(0.028702220187686*band7*band1 + 0.971297779812314*sin(band1))) + 0.0235599298084993*floor(0.995223926146334*sqrt(abs(0.028702220187686*band7*band1 + 0.971297779812314*sin(band1))) + 0.00477607385366598*abs(0.028702220187686*band7*band1 + 0.971297779812314*sin(band1))) - 0.180030905136552*cos(band4) + 0.0046635498889134*abs(0.028702220187686*band7*band1 + 0.971297779812314*sin(band1));
};
// formula for second class
function output_second(band7)
{
return band7;
};
// 5- transformation of bands values into 16bits values
var B04_16 = round(B04*65535);
var B01_16 = round(B01*65535);
var B07_16 = round(B07*65535);
// 6- comparison of the two formulas and return of the class
if (output_first(B04_16,B07_16, B01_16) < output_second(B07_16))
{
return(no_cloud);
}
else
{
return(cloud);
}