Normalized difference vegetation index with custom visualization, SkySat

//VERSION=3
// NDVI

function setup() {
  return {
    input: ["Red", "NIR", "dataMask"],
    output: [
      { id: "default", bands: 4 },
    ]
  }
}

function evaluatePixel(sample) {
  let NDVI = index(sample.NIR, sample.Red);
  let id_default = valueInterpolate(NDVI,
    [0, 0.2, 0.3, 0.4, 0.5, 1.0],
    [
      [1, 1, 0.88],
      [0.57, 0.75, 0.32],
      [0.44, 0.64, 0.25],
      [0.31, 0.54, 0.18],
      [0.19, 0.43, 0.11],
      [0.06, 0.33, 0.04],
      [0, 0.27, 0],
    ]);

  return {
    default: [...id_default, sample.dataMask],
  };
}
//VERSION=3
// NDVI

function setup() {
  return {
    input: ["Red", "NIR", "dataMask"],
    output: [
      { id: "default", bands: 4 },
      { id: "index", bands: 1, sampleType: "FLOAT32" },
      { id: "eobrowserStats", bands: 2, sampleType: "FLOAT32" },
      { id: "dataMask", bands: 1 },
    ]
  }
}

function evaluatePixel(sample) {
  let NDVI = index(sample.NIR, sample.Red);
  const indexVal = isFinite(NDVI) && sample.dataMask === 1 ? NDVI : NaN;
  let id_default = valueInterpolate(NDVI,
    [0, 0.2, 0.3, 0.4, 0.5, 1.0],
    [
      [1, 1, 0.88],
      [0.57, 0.75, 0.32],
      [0.44, 0.64, 0.25],
      [0.31, 0.54, 0.18],
      [0.19, 0.43, 0.11],
      [0.06, 0.33, 0.04],
      [0, 0.27, 0],
    ]
  );

  return {
    default: [...id_default, sample.dataMask],
    index: [indexVal],
    eobrowserStats: [indexVal, sample.dataMask],
    dataMask: [sample.dataMask],
  };
}
//VERSION=3
// NDVI

function setup() {
  return {
    input: ["Red", "NIR"],
    output: [
      { id: "default", bands: 1 },
    ]
  }
}

function evaluatePixel(sample) {
  let NDVI = index(sample.NIR, sample.Red);
  return { default: [NDVI] };
}

Evaluate and Visualize

The example data is using Planet Sandox data. This data is restricted to Sentinel Hub users with active paid plans. If you are already a Planet Customer, see here on how to get access.

General description

The well known and widely used NDVI is a simple, but effective index for quantifying green vegetation. It normalizes green leaf scattering in Near Infrared wavelengths with chlorophyll absorption in red wavelengths.

The value range of the NDVI is -1 to 1. Negative values of NDVI (values approaching -1) correspond to water. Values close to zero (-0.1 to 0.1) generally correspond to barren areas of rock, sand, or snow. Low, positive values represent shrub and grassland (approximately 0.2 to 0.4), while high values indicate temperate and tropical rainforests (values approaching 1). It is a good proxy for live green vegetation; see [1] for details.

The normalized difference vegetation index, abbreviated NDVI, is defined as

\[NDVI := \mathtt{Index}(nir,red) = \frac{nir-red}{nir+red}.\]

The result is visualized using the valueInterpolate function. It maps the values of the NDVI in certain intervals to RGBA (RGB+Alpha) values for visualization.

Description of representative images

NDVI visualisation over Rome, Italy, acquired on 2018/08/28.

NDVI

References

[1] Wikipedia, Normalized Difference Vegetation Index . Accessed on October 4th 2017.