N00bML's picture
Update README.md
103be26 verified

A newer version of the Gradio SDK is available: 6.13.0

Upgrade
metadata
title: NDVI Anomaly Detection
emoji: 🌿
colorFrom: green
colorTo: blue
sdk: gradio
sdk_version: 6.2.0
app_file: app.py
pinned: false
license: apache-2.0

🌿 NDVI Anomaly Detection

Detect vegetation anomalies in satellite imagery using Isolation Forest machine learning. This application monitors forest health by identifying unusual patterns in NDVI (Normalized Difference Vegetation Index) data from the Changa Manga Forest, Pakistan.

πŸš€ Quick Start

  1. Upload an NDVI image in GeoTIFF (.tif) format
  2. Click Submit to process
  3. View the anomaly map showing:
    • 🟒 Green areas: Normal, healthy vegetation
    • πŸ”΄ Red areas: Anomalous patterns (potential stress, disease, or damage)

πŸ“Š How It Works

This application uses a custom-trained Isolation Forest model that:

  1. Analyzes temporal patterns from 24 months of historical NDVI data
  2. Compares your uploaded image against learned normal vegetation patterns
  3. Identifies pixels that deviate significantly from expected values
  4. Generates a color-coded anomaly map with statistics

Technical Details

  • Algorithm: Isolation Forest (unsupervised anomaly detection)
  • Training Data: 24 monthly NDVI images from Changa Manga Forest
  • Input: Single-band GeoTIFF with NDVI values (-1.0 to 1.0)
  • Output: Side-by-side comparison of original NDVI and anomaly map
  • Model: Custom-trained using scikit-learn, saved as isolation_forest_ndvi.pkl

πŸ“ˆ Use Cases

  • Forest Health Monitoring: Detect areas of vegetation stress or disease
  • Deforestation Detection: Identify unusual clearing patterns
  • Agricultural Monitoring: Spot crop anomalies early
  • Environmental Research: Track vegetation changes over time
  • Climate Impact Studies: Monitor effects of weather events on vegetation

πŸ› οΈ About the Model

The Isolation Forest model was trained specifically for this project:

  • Dataset: 24 months of NDVI satellite imagery
  • Study Area: Changa Manga Forest, Pakistan
  • Data Source: Google Earth Engine
  • Framework: scikit-learn
  • Training: Custom-trained on temporal patterns to learn normal vegetation behavior

The model identifies anomalies by isolating observations that are easier to separate from the rest of the data, making it ideal for detecting unusual vegetation patterns.

πŸ“‚ Model Files

This Space includes:

  • app.py - Gradio interface application
  • isolation_forest_ndvi.pkl - Custom-trained Isolation Forest model
  • NDVI_Images/ - 24 training images (historical NDVI data)
  • requirements.txt - Python dependencies

πŸ’» Running Locally

Want to run this on your own machine?

# Clone the repository
git clone https://github.com/NoobML/ndvi-anomaly-detection.git
cd ndvi-anomaly-detection

# Install dependencies
pip install -r requirements.txt

# Run the app
python app.py

πŸ“– Full Documentation

For detailed documentation, training code, and more examples, visit the GitHub repository:

πŸ”— github.com/NoobML/ndvi-anomaly-detection

The GitHub repo includes:

  • Complete training scripts
  • Data preprocessing code
  • Google Earth Engine scripts for downloading NDVI data
  • Detailed technical documentation
  • Example datasets and outputs
  • Troubleshooting guides

🎯 Example Results

The application provides:

  • Visual Comparison: Original NDVI vs Anomaly Map
  • Statistics: Number and percentage of anomalous pixels
  • Color Coding: Intuitive red-green scale for easy interpretation
  • High Resolution: Pixel-level anomaly detection

βš™οΈ Requirements

numpy
rasterio
matplotlib
scikit-learn
gradio
joblib

πŸ“ Data Format

Input Requirements:

  • Format: GeoTIFF (.tif)
  • Bands: Single-band (NDVI only)
  • Value Range: -1.0 to 1.0 (standard NDVI scale)
  • Projection: Should match training data (ideally same study area)

Note: For best results, use NDVI images from similar geographic areas and time periods as the training data.

πŸ” Interpreting Results

Anomaly Map Colors:

  • Dark Red: Strong anomaly (highly unusual pattern)
  • Light Red/Orange: Mild anomaly
  • Yellow: Borderline normal
  • Light Green: Normal vegetation
  • Dark Green: Very normal (matches historical patterns closely)

Statistics:

The app displays the percentage of anomalous pixels, helping you quantify the extent of unusual vegetation patterns.

🀝 Contributing

Found a bug? Have a feature request?

  • Report issues: GitHub Issues
  • Contribute: Fork the repo and submit a pull request
  • Discuss: Use the Community tab on this Space

🌍 About the Study Area

Changa Manga Forest is one of the largest man-made forests in the world, located in Punjab, Pakistan. Monitoring its vegetation health is crucial for:

  • Biodiversity conservation
  • Climate regulation
  • Local community livelihoods
  • Research and education

πŸ“§ Contact

πŸ“„ License

This project is licensed under the Apache 2.0 License.


πŸ™ Acknowledgments

  • Data Source: Google Earth Engine
  • ML Framework: scikit-learn
  • Interface: Gradio by Hugging Face
  • Study Area: Changa Manga Forest, Pakistan

⭐ If you find this Space useful, please give it a like and share it with others interested in remote sensing and vegetation monitoring!


πŸ“š Related Projects

Interested in satellite imagery analysis and environmental monitoring? Check out other Spaces and resources:

  • Explore more on GitHub
  • Learn about NDVI and remote sensing
  • Discover Google Earth Engine for satellite data

This is a research and educational tool. For critical applications, results should be validated with ground truth data and expert analysis.