Spectral Index Segmentation
Overview
Multispectral satellites capture bands beyond visible RGB (NIR, red-edge, SWIR). Normalized difference indices combine these bands into single-channel images where target features (water, vegetation, chlorophyll) have distinct value ranges. A simple threshold on the index produces a binary segmentation mask without any ML model.
Quick Start
import numpy as np
from skimage.transform import resize
def ndwi(green, nir):
return (green - nir) / (green + nir + 1e-10)
def ccci(red, red_edge, mir):
return ((mir - red_edge) / (mir + red_edge + 1e-10) *
(mir - red) / (mir + red + 1e-10))
def ndvi(red, nir):
return (nir - red) / (nir + red + 1e-10)
ms = load_16band_image(image_id)
re = resize(ms[5], rgb.shape[:2])
mir = resize(ms[7], rgb.shape[:2])
r = rgb[:, :, 0].astype(float)
index = ccci(r, re, mir)
water_mask = (index > 0.11).astype(np.uint8)
Workflow
- Load multispectral bands and resize to a common spatial resolution
- Select bands for the target index (e.g., green+NIR for NDWI)
- Compute the normalized ratio — values typically range [-1, 1]
- Threshold to produce a binary mask
- Optionally apply morphological cleaning (opening/closing)
Key Decisions
- Index choice: NDWI for water, NDVI for vegetation, CCCI for chlorophyll/waterways
- Threshold tuning: varies by sensor, scene, and season — tune on labeled samples
- Band alignment: always resize lower-res bands to match before computing indices
- vs ML models: spectral indices are interpretable baselines; often competitive for simple targets