Skip to content

Lalitgis/CropSense

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CropSense — Multispectral Vegetation Index Calculator for QGIS

CropSense Logo

QGIS Python License Version Platform


CropSense is a free, open-source QGIS plugin for calculating vegetation indices from UAV/drone multispectral imagery. Designed for precision agriculture researchers, agronomists, and crop scientists, it automates the entire workflow — from scanning date-wise image folders to computing 22+ indices and saving analysis-ready GeoTIFFs — in a single, easy-to-use interface.

Built for studies involving nitrogen management, crop health monitoring, and multi-temporal field analysis.


Table of Contents


Features

  • 22+ built-in vegetation indices — covering nitrogen, biomass, chlorophyll, soil adjustment, water stress, and LAI
  • Custom index formula builder — write your own indices using band names and numpy functions, with live validation
  • Dropdown formula builder — compose formulas visually by clicking band and operator buttons
  • Multi-TIF support — handles multiple stacked GeoTIFFs per date folder (different sensors or flights)
  • Automatic band detection — reads wavelength tags, band descriptions, and Pix4D/Metashape metadata to assign bands; falls back to positional order
  • Manual band override — correct any wrong assignment through the Band Inspector table
  • Batch processing — processes all date folders in one run; outputs organised by date and sensor
  • Selective processing — enable or disable individual TIF files from the tree view before running
  • Auto-load into QGIS — optionally adds all output layers directly to the QGIS Layers panel
  • Live progress log — real-time feedback with mean and std values per index per date
  • Thread-safe — scanning and processing run in background threads; UI stays responsive
  • Zero-safe division — all formulas use safe division to prevent NaN/inf artefacts
  • LZW-compressed output — compact float32 GeoTIFFs with full CRS and geotransform preserved

Screenshots

image
Tab Description
📁 Data Input Scan folders, view detected TIFs in a tree, enable/disable each
🔬 Band Inspector Review and override auto-detected band assignments per TIF
📊 Index Selection 22 built-in indices grouped by category with quick-select buttons
🧮 Custom Builder Dropdown + text formula builder with live validation
💾 Output & Run Set output folder, options, run preview, and launch
📋 Log Real-time progress, mean/std results, error messages

Supported Vegetation Indices

Nitrogen-Sensitive

Index Formula Use Case
NDRE (NIR − RE) / (NIR + RE) Best overall N-nutrition indicator (LNC, LNA, PNC, PNA)
GNDVI (NIR − G) / (NIR + G) Chlorophyll & N uptake; saturates later than NDVI
MCARI [(RE−R) − 0.2(RE−G)] × (RE/R) Highest SPAD correlation in rice canopy (R=0.91)
LCI (NIR − RE) / (NIR + R) Leaf chlorophyll index at full canopy
CVI NIR × R / G² Leaf chlorophyll concentration
RENDVI (RE − R) / (RE + R) Stress detection in dense canopy

Broadband Greenness

Index Formula Use Case
NDVI (NIR − R) / (NIR + R) Biomass & overall vigour baseline
RVI NIR / R Simple ratio biomass indicator
DVI NIR − R Linear biomass sensitivity
IPVI NIR / (NIR + R) Always-positive NDVI form
BNDVI (NIR − B) / (NIR + B) Low soil background noise
WDRVI (0.1×NIR − R) / (0.1×NIR + R) Reduces NDVI saturation at high LAI

Canopy & Stress

Index Formula Use Case
EVI 2.5 × (NIR−R) / (NIR + 6R − 7.5B + 1) Soil & atmosphere corrected
EVI2 2.5 × (NIR−R) / (NIR + 2.4R + 1) Two-band EVI, no blue required
ARVI (NIR−(2R−B)) / (NIR+(2R−B)) Aerosol-resistant
SIPI (NIR − B) / (NIR − R) Carotenoid to chlorophyll ratio

Soil-Adjusted

Index Formula Use Case
SAVI 1.5 × (NIR−R) / (NIR + R + 0.5) Early season / sparse canopy
OSAVI (NIR−R) / (NIR + R + 0.16) No manual L parameter needed
MSAVI [2NIR+1 − √((2NIR+1)²−8(NIR−R))] / 2 Auto soil correction

Water & Moisture

Index Formula Use Case
NDWI (G − NIR) / (G + NIR) Open water detection
NDMI (NIR−G) / (NIR+G+RE) Plant water stress (5-band proxy)

LAI

Index Formula Use Case
LAI_NDVI 3.618 × NDVI − 0.118 Leaf Area Index empirical proxy

Installation

Method 1 — Install from ZIP (recommended)

  1. Download CropSense from the Releases page
  2. Open QGIS
  3. Go to Plugins → Manage and Install Plugins → Install from ZIP
  4. Select the downloaded ZIP → click Install Plugin
  5. The plugin appears under Raster → Multispectral VI Calculator → VI Calculator

Method 2 — Manual installation

Copy the CropSense/ folder into your QGIS plugins directory:

Operating System Plugin Directory
Windows %APPDATA%\QGIS\QGIS3\profiles\default\python\plugins\
macOS ~/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/
Linux ~/.local/share/QGIS/QGIS3/profiles/default/python/plugins/

Then enable it in Plugins → Manage and Install Plugins → Installed.

Tip for Windows users: Press Win + R, type %APPDATA%, press Enter, then navigate to QGIS\QGIS3\profiles\default\python\plugins\.


Folder Structure

CropSense expects your data to be organised in date-wise sub-folders, each containing one or more stacked multispectral GeoTIFFs:

DataRoot/                          ← Select this as your root folder
    08-26/
        orthomosaic.tif            ← Stacked 5-band GeoTIFF (sensor A)
        reflectance.tif            ← Optional second TIF (sensor B)
    09-10/
        orthomosaic.tif
    09-25/
        orthomosaic.tif
    10-08/
        orthomosaic.tif

Each folder should contain 5 bands: Blue, Green, Red, Red Edge, NIR (standard for DJI Phantom 4 Multispectral, MicaSense RedEdge, Parrot Sequoia).

4-band sensors (no Red Edge) are also supported — indices requiring Red Edge will simply be skipped for those files.


How to Use

Step 1 — Scan your data

  1. Open the plugin from Raster → Multispectral VI Calculator → VI Calculator
  2. In Tab 1 (Data Input), click Browse and select your root data folder
  3. Click Scan Folder
  4. The plugin displays all detected date folders and TIF files in a tree view
  5. Tick or untick the checkbox next to each TIF to include or exclude it from the run

Step 2 — Inspect band assignments

  1. Click any TIF row in the tree to open the Band Inspector (Tab 2)
  2. Review how each raster band was identified (wavelength tag, description, or positional)
  3. Use the Override dropdown to correct any wrong assignment
  4. Click Apply Overrides to save changes

Step 3 — Select indices

  1. Go to Tab 3 (Indices)
  2. Check the indices you want to calculate
  3. Use quick-select buttons: All / None / Nitrogen / Greenness / Canopy / Soil / Water

Step 4 — Add custom indices (optional)

  1. Go to Tab 4 (Custom Builder)
  2. Use Option A (dropdown builder) to compose a formula by clicking buttons
  3. Or use Option B (text box) to type a formula directly
  4. Click Validate to test the formula, then Add to Run List

Step 5 — Set output and run

  1. Go to Tab 5 (Output & Run)
  2. Click Browse to select your output folder
  3. Toggle options: auto-load into QGIS, overwrite existing files
  4. Click Refresh Preview to confirm what will be calculated
  5. Click ▶ Run VI Calculation

Step 6 — Review results

  1. Go to Tab 6 (Log) to see live progress
  2. After completion, mean and standard deviation per index per date are shown
  3. All output GeoTIFFs are saved and (optionally) loaded into QGIS automatically

Custom Index Builder

Write any vegetation index using standard band names:

BLUE    GREEN    RED    REDEDGE    NIR

Available functions

safe_div(numerator, denominator)   # Zero-safe division (recommended for all ratios)
np.sqrt()    np.clip()    np.log()
np.exp()     np.abs()     np.maximum()    np.minimum()

Example formulas

# NDVI
safe_div(NIR - RED, NIR + RED)

# EVI
2.5 * safe_div(NIR - RED, NIR + 6 * RED - 7.5 * BLUE + 1)

# Custom chlorophyll index
safe_div(REDEDGE - RED, REDEDGE + RED + GREEN)

# Clip result to a range
np.clip(3.618 * safe_div(NIR - RED, NIR + RED) - 0.118, 0.0, 10.0)

Output Structure

Results/                                    ← Your chosen output folder
    08-26/
        orthomosaic/
            08-26_orthomosaic_NDRE.tif
            08-26_orthomosaic_GNDVI.tif
            08-26_orthomosaic_NDVI.tif
            08-26_orthomosaic_MCARI.tif
            08-26_orthomosaic_EVI.tif
            ...
        reflectance/
            08-26_reflectance_NDRE.tif
            ...
    09-10/
        orthomosaic/
            09-10_orthomosaic_NDRE.tif
            ...

All outputs are float32 GeoTIFFs with:

  • Full CRS and geotransform from the source image
  • LZW compression
  • NaN as NoData value
  • Values clipped to [-1, 1] for normalised indices

Band Auto-Detection

CropSense automatically identifies which raster band corresponds to which spectral channel using a four-tier priority system:

Priority Method Example
1 Wavelength tags in rasterio metadata wavelength = 560 → GREEN
2 Band description strings "Red Edge" → REDEDGE
3 Pix4D / Metashape / DJI band name tags BandName = NIR → NIR
4 Positional fallback Band 4 → REDEDGE (standard order)

If auto-detection is wrong, you can manually override any band assignment in the Band Inspector tab without re-scanning.


Requirements

Dependency Version Notes
QGIS ≥ 3.16 Tested on 3.22, 3.28, 3.34, 3.38
Python ≥ 3.9 Bundled with QGIS
numpy ≥ 1.20 Bundled with QGIS
rasterio ≥ 1.3 Install separately if needed

Installing rasterio

If QGIS cannot find rasterio, install it through the OSGeo4W Shell (Windows):

pip install rasterio

On macOS/Linux:

pip3 install rasterio --break-system-packages

Contributing

Contributions are welcome. To contribute:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-new-index
  3. Make your changes and test in QGIS
  4. Run the syntax check: python3 -m pyflakes *.py
  5. Submit a Pull Request with a clear description

Ideas for contribution

  • Additional vegetation indices
  • Support for hyperspectral sensors (>5 bands)
  • Field boundary drawing tool (Phase 2)
  • Per-plot value extraction and CSV export (Phase 2)
  • Time-series plotting of VI values across dates
  • Integration with QGIS Processing framework

Citation

If you use CropSense in your research, please cite it as:

@software{cropsense2025,
  title     = {CropSense: Multispectral Vegetation Index Calculator for QGIS},
  author    = {Map Mentors (Lalit BC)},
  year      = {2025},
  version   = {1.0.0},
  url       = {https://github.com/Lalitgis/cropsense},
  note      = {QGIS Plugin for UAV multispectral image analysis}
}

Key references for indices used

  • Rouse et al. (1974) — NDVI
  • Gitelson & Merzlyak (1996) — GNDVI
  • Barnes et al. (2000) — NDRE
  • Daughtry et al. (2000) — MCARI
  • Huete et al. (2002) — EVI
  • Rondeaux et al. (1996) — OSAVI

Roadmap

  • 22 built-in vegetation indices
  • Custom formula builder (text + dropdown)
  • Multi-TIF per date folder support
  • Automatic band detection from metadata
  • Manual band override interface
  • Batch processing with progress log
  • Field boundary drawing tool
  • Per-plot value extraction
  • Smart CSV exporter (mean/std/min/max per plot per VI per date)
  • Time-series VI trend plots
  • QGIS Processing provider integration
  • Hyperspectral sensor support

License

CropSense is released under the GNU General Public License v3.0. See LICENSE for full terms.


Made for precision agriculture research  |  Built with QGIS & Python

About

CropSense - GitHub Repository for drone based remote sensing and vegetation indices calculation plugin for QGIS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages