//== PARAMETERS ===========================varc0r=0.036;// amount of atmosphere we're compensating//var cManual = [0.039, 0.071, 0.121]; // manual white point//var cManual = [[0.039, 0.96], [0.071, 0.84], [0.121, 1.34]]; // manual black & white pointvartx=0.2;// ty/tx ~ contrast in dark areasvarty=0.4;// (1-ty)/(1-tx) ~ contrast in light areasvarmax=3.1;// reflectance that will become whitevarsat=1.3;// saturation enhancementvardebug=false;// Set to 'true' to highlight out-of-range valuesvaratmRatios=[1,2,3.25];// Rayleigh-derived consts for automated atmosphere offsets//== FUNCTIONS ============================varsRGBenc=C=>C<0.0031308?(12.92*C):(1.055*Math.pow(C,0.41666)-0.055);// atmospheric adjustmentvaratm2p=(a,c0,c1)=>(a-c0)/c1;varatm1p=(a,c0)=>atm2p(a,c0,(1-c0)**2);varatm=(a,ii)=>(typeofcManual!=='undefined')?(cManual[ii]instanceofArray)?atm2p(a,cManual[ii][0],cManual[ii][1]):atm1p(a,cManual[ii]):atm1p(a,c0r*atmRatios[ii]);//contrast enhancementvaradjFun=(a,tx,ty,max)=>{varar=a/max;vartxr=tx/max;varbot=(2*txr-1)*ar-txr;returnar*(1+(txr-ty)*(1-ar)/bot);};varadj=a=>adjFun(a,tx,ty,max);varsatEnh=rgbArr=>{varavg=rgbArr.reduce((a,b)=>a+b,0)/rgbArr.length;returnrgbArr.map(a=>avg*(1-sat)+a*sat);};varcheckDebug=arr=>{if(!debug){returnarr;}varmaxC=Math.max.apply(null,arr);varminC=Math.min.apply(null,arr);return(minC<0)// Highlight too dark pixels?arr.map(a=>a<0?1:0):(maxC>1)// Highlight too bright pixels?(minC>1)?arr.map(a=>(a-1)/(maxC-1)):arr.map(a=>a>1?1:0):arr;};//== SCRIPT ============================varrgb=satEnh([B04,B03,B02].map(atm).map(adj));returncheckDebug(rgb).map(sRGBenc);
cManual: (optional) manual offsets for r,g,b bands; may include manual scale factors as well
tx, ty: position of the mid-point of the envelope for the levels color adjustment curve
max: maximal band value (after atmospheric compensation), to be rendered as white
sat: saturation enhancement, applied after levels adjustment
debug: set to false to highlight pixels where any component is outside the interval [0..1]
atmRatios: band offset ratios to use with single-parameter atmospheric correction (defaults are derived from Rayleigh scattering)
General description
The product produces natural color images using Sentinel-2 bands 4, 3 and 2. It performs a very basic linear atmospheric correction, and applies a curve to the color components to enhance details in the dark areas, while preserving contrast in very bright snow-covered slopes. It has been fine-tuned to use on the Sentinel-2 image of Monte Sarmiento in Tierra del Fuego taken 2016-05-05.