Hello,
I know this problem might not be absolutely relevant here but I am struggling a lot and not being able to find solutions hence asking here.
I want to do batch FUI processing of my sentinel 2 satellite images, however, they are >500 in no. so i don’t want to download them and do in SNAP. Hence, i am trying to do it using GEE. However, I followed many of the standard and reputed publications, and customised the code for S2 10m. But When I am cross-validating it using SNAP’s FUI, the hue angle and FUI values are way different. I am pasting the main function for FUI (done in GEE) here, can anybody please guide how to achieve the same results as SNAP, given the output of SNAP is correct even for high-mountain (>4500m. asl) small inland lakes.
The function:
function computeFUI(img2) {
// Select and rename bands for clarity.
var r = img2.select([‘B1’, ‘B2’, ‘B3’, ‘B4’, ‘B5’]).divide(10000);
//Tristimulus values (OLI)
var X = r.expression(
‘8.856b1 + 12.040b2 + 53.696b3 + 32.087b4 + 0.487b5’,
{‘b1’: r.select(‘B1’), ‘b2’: r.select(‘B2’), ‘b3’: r.select(‘B3’), ‘b4’: r.select(‘B4’), ‘b5’: r.select(‘B5’)}
);
var Y = r.expression(
'0.993b1 + 23.122b2 + 65.702b3 + 16.830b4 + 0.177b5’,
{‘b1’: r.select(‘B1’), ‘b2’: r.select(‘B2’), ‘b3’: r.select(‘B3’), ‘b4’: r.select(‘B4’), ‘b5’: r.select(‘B5’)}
);
var Z = r.expression(
‘43.487b1 + 61.055b2 + 1.778b3 + 0.015b4’,
{‘b1’: r.select(‘B1’), ‘b2’: r.select(‘B2’), ‘b3’: r.select(‘B3’), ‘b4’: r.select(‘B4’)}
);
// Chromaticity coordinates
var denom = X.add(Y).add(Z);
var x = X.divide(denom);
var y = Y.divide(denom);
var dx = x.subtract(1/3);
var dy = y.subtract(1/3);
// Hue Angle Formula
var alpha = dx.atan2(dy) // This returns radians
.mod(2 * Math.PI) // Modulo 2π
.multiply(180 / Math.PI); // Convert to degrees
// Δα correction
var alpha_norm = alpha.divide(100);
var delta_alpha = alpha_norm.pow(5).multiply(a)
.add(alpha_norm.pow(4).multiply(b))
.add(alpha_norm.pow(3).multiply(c))
.add(alpha_norm.pow(2).multiply(d))
.add(alpha_norm.multiply(e))
.add(f);
var alpha_corrected = alpha.add(delta_alpha).mod(360);
//FUI classification
var fui = ee.Image(0).rename(‘FUI’);
fui_classes.forEach(function(c) {
fui = fui.where(
alpha_corrected.gte(c.min).and(alpha_corrected.lt(c.max)),
c.class
);
});
return ee.Image.cat([
alpha_corrected.rename(‘hue_angle’),
fui.toByte().rename(‘FUI’)
]).copyProperties(img2, [‘system:time_start’]);
}
var FUI = Rrs.map(computeFUI);
The difference for example, hue angle=215.01163, FUI=3 in SNAP; hue angle=130.3291, FUI=7 in the code in GEE. The lake is dark blue in true colour composite.
Thank you very much.
Soumi