Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Difference-Index-Calculator-QGIS-Toolbox

A QGIS Processing toolbox script that calculates any normalized difference spectral index from one or two raster layers using the normalized Difference Index

Repositori di GitHub

Author: Defani Arman Alfitriansyah Date: June 11, 2026 Version: 1.0.0 GitHub: https://github.com/Defani/Difference-Index-Calculator-QGIS-Toolbox Compatible: QGIS 3.16+


Overview

A QGIS Processing toolbox script that calculates any normalized difference spectral index from one or two raster layers using the universal formula:

NDI=Band A−Band BBand A+Band B\text{NDI} = \frac{\text{Band A} - \text{Band B}}{\text{Band A} + \text{Band B}}

Common indices you can calculate:

IndexBand ABand BTypical Use
NDVINIRRedVegetation health
NDWIGreenNIRWater body mapping
MNDWIGreenSWIRModified water index
NDBISWIRNIRBuilt-up area mapping
NBRNIRSWIRBurn severity
NDSIGreenSWIRSnow mapping
CustomAnyAnyAny user-defined index

This tool is part of the Remote Sensing Tools group in the QGIS Processing Toolbox — alongside the Spectral Value Extractor.


Key Features


Installation

Step 1 — Download the Script

Download NormalizedDifferenceIndexCalculator_script.py from this repository (click Code → Download ZIP or clone with git).

git clone https://github.com/Defani/Difference-Index-Calculator-QGIS-Toolbox.git

Step 2 — Add Script to Processing Toolbox

Open Processing → Toolbox, click the Python icon (⚙️) at the top of the Toolbox panel, and select Add Script to Toolbox...


Step 3 — Browse and Select the Script File

Navigate to where you saved NormalizedDifferenceIndexCalculator_script.py and click Open.


Step 4 — Find the Tool in the Toolbox

The tool will appear under:

Processing Toolbox
└── Scripts
    └── Remote Sensing Tools
        └── Normalized Difference Index Calculator

Double-click to open the dialog.


Usage

Step 5 — Fill in the Parameters

ParameterDescription
Preset IndexOptional dropdown — select an index to see a hint about which band should go in Band A and which in Band B. Does not auto-fill the band numbers.
Raster for Band ASelect the raster layer containing Band A (e.g. a NIR band)
Band ABand number within Raster A (default: 1)
Raster for Band BSelect the raster layer containing Band B — can be the same file as Band A
Band BBand number within Raster B (default: 1)
Output Index NameName for the output, e.g. NDVI, NDWI, CustomIndex
Output RasterFile path for the output GeoTIFF

Step 6 — Understanding the Preset Dropdown

The Preset Index dropdown is a guidance tool — it shows a hint in the processing log telling you which band should go in Band A and which in Band B. You still assign the band numbers manually, which gives you full flexibility with any satellite sensor.

Example presets:

PresetBand ABand B
NDVINIR bandRed band
NDWIGreen bandNIR band
MNDWIGreen bandSWIR band
NDBISWIR bandNIR band
NBRNIR bandSWIR band

Step 7 — Auto-Resample Behavior

If Band A and Band B come from rasters with different pixel resolutions (e.g. 10 m vs 20 m), the tool will:

  1. Detect which raster has the finer (smaller pixel) resolution

  2. Resample the coarser raster to match the finer grid using bilinear interpolation

  3. Compute the index on the harmonized grid

  4. The output resolution matches the finest input resolution

This is reported in the processing log:

Pixel area A: 100.000000  |  Pixel area B: 400.000000
Raster B has coarser resolution (or different CRS). Resampling Band B → Band A grid (bilinear).

Step 8 — Run and Check the Log

Click Run. The log will show:

Preset hint: NIR band → Band A  |  Red band → Band B
Index name  : NDVI
Band A      : band 4 from 'Sentinel2_10m'
Band B      : band 3 from 'Sentinel2_10m'
Same resolution and CRS — no resampling needed.
Result  min : -0.312500
Result  max :  0.891200
Result mean :  0.423700
✔ Layer 'NDVI' added to QGIS.
✔ Done! 'NDVI' saved to: C:/output/NDVI.tif

Step 9 — Output Layer

Once finished, the output raster is automatically added to the QGIS Layers panel with the name you specified (e.g. NDVI). The output is a single-band Float32 GeoTIFF compressed with LZW.


Parameters Reference

ParameterTypeDescription
Preset IndexEnum (optional)Guidance hint — shows band assignment in the log
Raster for Band ARaster LayerInput raster containing Band A
Band ABand NumberBand index in Raster A
Raster for Band BRaster LayerInput raster containing Band B (can equal Raster A)
Band BBand NumberBand index in Raster B
Output Index NameStringName used for the QGIS layer and GeoTIFF band description
Output RasterRaster DestinationOutput GeoTIFF file path

Outputs

OutputDescription
Output RasterFloat32 GeoTIFF, values in [−1, 1], NoData = −9999
Minimum valueMinimum valid pixel value
Maximum valueMaximum valid pixel value
Mean valueMean valid pixel value

Technical Notes


Requirements


ToolDescription
Spectral Value ExtractorExtracts raster pixel values at field sample point locations, exports to CSV and new point layer

License

MIT License — free to use, modify, and distribute.