Magic Eyes

//VERSION=3
//Combination of NIR, SWIR and visible Red band to create a visualization that aids visual interpretation of Land Cover from Sentinel-2 images. Based on a band combination used for creating CORINE Land Cover maps.
//By András Zlinszky, Sinergise - with help from GitHub Copilot, based on code by Ottó Petrik from Lechner Institute, Hungary.
//https://bsky.app/profile/azlinszky.bsky.social
function setup() {
    return {
    input: ["B02","B03","B08","B11","B04", "dataMask"],
    output: { bands: 4 }
    };
    }
    
    //this is the gain for the image. Increase for a brighter image. If you are using Sentinel-2 monthly mosaics, divide by 10000, eg the default value would be 0.00025
    const gain = 2.5
    //this is the weighting between the SWIR Band 11 and the panchromatic band. Increase it for more sharpness, decrease it to stay closer to B11 values
    const weighting = 0.25
    
    function evaluatePixel(sample) {
          let pan = (sample.B02 + sample.B03 + sample.B04 + sample.B08) / 4;
    return [gain * sample.B08, (((1 - weighting) * gain) * sample.B11 + weighting * gain * pan), gain * sample.B04, sample.dataMask];
    }

Evaluate and Visualize

General description of the script

This script is based on a band combination that is regularly used for visual interpretation of satellite imagery: NIR, SWIR and Red assigned to Red, Green and Blue respectively. The aim is to make areas that are different in reality also look different on the visualization, but not to create a scene that is close to true color. This is achieved by using three bands from rather different parts of the optical spectrum (NIR, SWIR and VIS), providing independent measurements of the spectral characteristics of each pixel. However, since Band 11 has a reduced resolution compared to Band 4 and Band 8, we have added a simple pansharpening effect. This was created by simulating a “panchromatic band”, calculating the mean of Bands 2, 3, 4, and 8, and adding those values to Band 11. The intensity of this pansharpening can be modified using a simple weighting factor. Additionally, the brightness of the image can be adjusted with a simple gain factor.

Description of representative images

This image shows the Polish-German-Czech triple border on 8 March 2025. Vegetation is bright red to orange and yellow depending on its greenness, deep red areas are coniferous forests. Snow is pink and ice is purple. Open water areas and fresh lava surfaces are black. Urban areas and roads are shown in various shades of grey. Active fires and other hot areas are bright neon green.

'Sentinel-2 Magic Eye custom script image from 8 March 2025'