Sentinel-2 Simple Panchromatic

//VERSION=3
//Simple Panchromatic visualization of Sentinel-2 data, using the mean of the band intensities for Red, Green, Blue and Near Infrared
//By András Zlinszky, Sinergise - with help from GitHub Copilot
//https://bsky.app/profile/azlinszky.bsky.social

function setup() {
    return {
      input: ["B01", "B02", "B03", "B08", "dataMask"],
      output: { bands: 4 }
    };
  }
  
  const gain = 2.5;
  
  function evaluatePixel(sample) {
    // Calculate the mean of the bands
    let pan = (sample.B01 + sample.B02 + sample.B03 + sample.B08) / 4;
  
    return [gain * pan, gain * pan, gain * pan, sample.dataMask];
  }
//VERSION=3
//Simple Panchromatic visualization of Sentinel-2 data, using the mean of the band intensities for Red, Green, Blue and Near Infrared
//By András Zlinszky, Sinergise - with help from GitHub Copilot
//https://bsky.app/profile/azlinszky.bsky.social

function setup() {
    return {
      input: ["B01", "B02", "B03", "B08", "dataMask"],
      output: { bands: 4 }
    };
  }
  
  const gain = 0.00025;
  
  function evaluatePixel(sample) {
    // Calculate the mean of the bands
    let pan = (sample.B01 + sample.B02 + sample.B03 + sample.B08) / 4;
  
    return [gain * pan, gain * pan, gain * pan, sample.dataMask];
  }

Evaluate and Visualize

General description of the script

This script is for creating a simple panchromatic greyscale visualization from Sentinel-2. It simulates the way a panchromatic band works by taking the average of bands 2 (Red), 3 (Green), 4 (Blue), and 8 (wide-band near infrared). The suggested use is for backgrounds in a scene compare, or as an input for pansharpening of lower resolution bands. The script also works for quarterly cloudless mosaics. Using the “opacity” function in compare mode and a panchromatic Sentinel-2 cloudless mosaic as a background, you can make the interpretation of low-resolution datasets such as Sentinel-3 or Sentinel-5P imagery a lot easier.

Description of representative images

This scene is a Sentinel-2 image of Nairobi, Kenya

'Sentinel-2 simple panchromatic image of Nairobi, Kenya on 3 March 2025'