Computer Vision for Precision Forestry with Satellite Imagery: A Production Pipeline
How to build production-grade computer vision pipelines for precision forestry using multi-spectral satellite imagery, tile-based processing, transfer learning, and geospatial databases. Lessons from deploying at scale.
Computer Vision for Precision Forestry with Satellite Imagery: A Production Pipeline
Satellite imagery analysis for forestry is one of the most rewarding applications of computer vision I’ve worked on in my nine-year career. It’s also one of the most technically demanding — you’re dealing with multi-spectral data that doesn’t behave like natural images, geographic scales that span millions of hectares, and domain constraints that can make or break a model’s usefulness. This post documents the architecture, tools, and hard-won lessons from building production CV pipelines for precision forestry.
The Problem Space: Why Forestry Needs Computer Vision
Precision forestry requires answering questions like: Where is deforestation occurring? What is the species composition of a forest stand? Where is pest infestation spreading? What is the biomass density? Historically, these questions were answered through manual field surveys — expensive, slow, and limited in spatial coverage. Satellite imagery changes the game entirely, but extracting actionable intelligence from terabytes of multi-spectral imagery requires sophisticated computer vision pipelines.
The core challenges are:
- Scale: A single Sentinel-2 tile covers 100km × 100km at 10-meter resolution. Monitoring a national forest means processing thousands of tiles, each with 13 spectral bands.
- Cloud cover: Tropical forests — where deforestation monitoring is most critical — have persistent cloud cover that can exceed 60% in some months.
- Temporal dynamics: Forests change slowly but continuously. A useful system must distinguish between seasonal variation (leaf phenology) and genuine change (deforestation, fire, pest damage).
- Domain specificity: Standard ImageNet-pretrained models don’t understand near-infrared reflectance, NDVI, or the spectral signature of degraded forest canopy. You need domain-specific approaches.
Multi-Spectral Image Processing
Understanding the Spectral Bands
Sentinel-2 provides 13 spectral bands at varying spatial resolutions:
- Visible bands (B2, B3, B4): 10m resolution — Blue, Green, Red. These look like normal RGB images and are useful for visual interpretation.
- Near-infrared (B8): 10m resolution — Critical for vegetation analysis. Healthy vegetation reflects strongly in NIR, making it invaluable for distinguishing forest from non-forest.
- Red Edge bands (B5, B6, B7, B8A): 20m resolution — Sensitive to chlorophyll content and useful for species discrimination.
- Short-wave infrared (B11, B12): 20m resolution — Sensitive to moisture content, useful for detecting stressed vegetation and fire scars.
- Atmospheric bands (B1, B9, B10): 60m resolution — Used primarily for atmospheric correction.
Vegetation Indices as Features
Raw spectral bands are useful, but derived indices capture domain knowledge more effectively:
- NDVI (Normalized Difference Vegetation Index): (B8 - B4) / (B8 + B4) — The workhorse of vegetation analysis. Healthy forest has NDVI > 0.7; bare soil and water have NDVI < 0.2.
- NDWI (Normalized Difference Water Index): (B3 - B8) / (B3 + B8) — Detects water bodies and moisture stress.
- EVI (Enhanced Vegetation Index): Reduces atmospheric and soil background effects compared to NDVI.
- NBR (Normalized Burn Ratio): (B8 - B12) / (B8 + B12) — Excellent for detecting fire scars and post-fire recovery.
In my pipeline, I compute these indices as additional channels and stack them with the raw bands to create a 17-channel input tensor. The model learns to use these derived features automatically, but providing them explicitly accelerates convergence and improves performance by 3-5% in mAP.
Atmospheric Correction
Raw satellite imagery includes atmospheric effects (haze, aerosols, water vapor) that introduce noise. I use Sen2Cor for Sentinel-2 atmospheric correction, which converts Top-of-Atmosphere (TOA) reflectance to Bottom-of-Atmosphere (BOA) reflectance. This step is non-negotiable for any quantitative analysis — models trained on TOA data will learn atmospheric artifacts as features and fail when atmospheric conditions change.
Cloud and Shadow Masking
Cloud masking is one of the most critical preprocessing steps. A cloud pixel that’s misclassified as clear land will produce a false deforestation signal. I use a combination of:
- s2cloudless: Sentinel-2’s built-in cloud probability layer, which works well for thick clouds but struggles with thin cirrus and cloud shadows.
- FMask (Function of Mask): A physics-based algorithm that uses spectral thresholds to identify clouds, cloud shadows, snow, and water.
- A custom U-Net model trained on manually annotated cloud masks. This catches edge cases that rule-based methods miss.
In production, I apply all three and use a union strategy — if any method flags a pixel as cloudy, I exclude it. This is conservative (you lose some clear pixels) but prevents false positives in downstream analysis.
Tile-Based Processing Pipeline
Why Tiles?
Satellite images are enormous. A single Sentinel-2 scene at 10m resolution is approximately 10,980 × 10,980 pixels per band — far too large to feed directly into a standard CNN. The solution is tile-based processing: divide the image into smaller patches (typically 256×256 or 512×512 pixels), process each tile independently, and reassemble the results.
My Tile Pipeline Architecture
Raw Sentinel-2 L1C → Sen2Cor (atmospheric correction) → L2A product
→ Cloud masking → Invalid pixel removal
→ Tile generation (512×512, 50% overlap)
→ Per-tile inference with CV model
→ Tile stitching with overlap resolution
→ Georeferencing with rasterio
→ Vectorization of detection masks
→ PostGIS ingestion
The overlap is critical. Objects at tile boundaries get split across two tiles, and without overlap, you get fragmented detections. I use 50% overlap with a Non-Maximum Suppression (NMS) step during stitching to merge duplicate detections. The computational cost of processing 4x more tiles is worth the improvement in boundary detection quality.
Parallelization Strategy
Processing thousands of tiles requires serious parallelization. I use Dask distributed on a Kubernetes cluster. Each worker processes one tile at a time, and the tile generation step produces a Dask bag of tile coordinates that gets distributed across workers. A typical processing run for a 100km × 100km Sentinel-2 tile takes about 15 minutes on a 32-node cluster — fast enough for near-real-time deforestation monitoring.
Memory management tip: Sentinel-2 tiles with all 13 bands at 10m resolution (resampled) consume about 500MB per 512×512 tile. I use memory-mapped arrays (via rasterio with windowed reading) to avoid loading entire scenes into memory. This is essential for processing large areas without running into OOM errors.
Model Architecture: Transfer Learning for Satellite Imagery
The Challenge of Transfer Learning
Standard ImageNet pretrained models expect 3-channel RGB input. Satellite imagery has 13+ channels with very different statistical properties. You can’t simply replace the first convolutional layer and hope for the best — the pretrained weights for the first layer are tuned to RGB statistics and won’t help with multi-spectral data.
My Approach: Spectral-Spatial Architecture
I use a two-branch architecture:
- Spectral branch: A 1D convolutional network that processes each pixel’s spectral signature independently. This captures spectral patterns (like the characteristic NIR reflectance of healthy forest) without spatial context.
- Spatial branch: A ResNet-50 backbone pretrained on ImageNet, with the first convolutional layer replaced to accept the spectral branch’s output as input (effectively treating spectral features as “channels”).
The two branches are fused via concatenation followed by a series of 3×3 convolutions. This architecture lets the spatial branch leverage ImageNet pretrained weights for spatial pattern recognition (edges, textures, shapes) while the spectral branch learns domain-specific spectral features from scratch.
Performance: This dual-branch approach outperforms a single-branch ResNet-50 (trained from scratch on multi-spectral data) by 8-12% in mAP for forest cover classification and by 15-20% for rare class detection (pest infestation, illegal logging).
Detectron2 vs. YOLOv5: My Production Comparison
I’ve deployed both Detectron2 and YOLOv5 for satellite imagery tasks. Here’s my honest comparison:
Detectron2 (Mask R-CNN):
- Better for instance segmentation (individual tree crown delineation)
- Higher accuracy on small objects (individual trees in sparse canopy)
- Slower inference (~150ms per tile on a V100 GPU)
- More complex deployment (PyTorch + Detectron2 dependencies)
YOLOv5:
- Better for object detection (deforestation patches, logging roads)
- Faster inference (~25ms per tile on a V100 GPU)
- Simpler deployment (single ONNX model)
- Struggles with very small objects (< 10 pixels)
My recommendation: Use YOLOv5 for change detection and large-scale monitoring (speed matters when processing millions of tiles). Use Detectron2 for detailed analysis tasks like individual tree crown mapping where accuracy is more important than throughput.
PostGIS Integration: Making CV Results Geospatially Actionable
Raw pixel-level detections are useless to forestry managers. They need georeferenced vector data that can be overlaid on maps, combined with field data, and analyzed in GIS tools. This is where PostGIS comes in.
Vectorization Pipeline
After model inference, I convert detection masks to vector polygons using rasterio.features.shapes. Each polygon is assigned:
- Geographic coordinates (transformed from pixel space to WGS84/UTM)
- Detection confidence score
- Predicted class (forest, deforestation, degradation, water, bare soil)
- Acquisition date
- Satellite metadata (cloud cover, sun angle)
PostGIS Schema
CREATE TABLE detections (
id SERIAL PRIMARY KEY,
geom GEOMETRY(MultiPolygon, 4326),
class VARCHAR(50),
confidence FLOAT,
area_ha FLOAT GENERATED ALWAYS AS (ST_Area(geom::geography) / 10000) STORED,
acquisition_date DATE,
tile_id VARCHAR(20),
model_version VARCHAR(20),
created_at TIMESTAMP DEFAULT NOW()
);
CREATE INDEX idx_detections_geom ON detections USING GIST(geom);
CREATE INDEX idx_detections_class ON detections(class);
CREATE INDEX idx_detections_date ON detections(acquisition_date);
The spatial index is critical — without it, queries like “find all deforestation events within 5km of this national park boundary” would be impossibly slow on tables with millions of rows.
Temporal Analysis with PostGIS
One of the most powerful features of storing detections in PostGIS is temporal analysis. I use PostGIS window functions to track how forest cover changes over time:
WITH monthly_stats AS (
SELECT
tile_id,
DATE_TRUNC('month', acquisition_date) AS month,
class,
SUM(area_ha) AS area
FROM detections
WHERE confidence > 0.7
GROUP BY tile_id, DATE_TRUNC('month', acquisition_date), class
)
SELECT
month,
class,
SUM(area) AS total_area_ha,
SUM(area) - LAG(SUM(area)) OVER (PARTITION BY class ORDER BY month) AS change_ha
FROM monthly_stats
GROUP BY month, class
ORDER BY month, class;
This gives forestry managers a clear view of deforestation trends, reforestation progress, and forest degradation patterns over time.
Lessons Learned from Production Deployment
Lesson 1: Label Quality Matters More Than Model Architecture
I spent months trying different model architectures before realizing that the bottleneck was label quality. Satellite imagery labeling requires domain expertise — distinguishing between natural forest gaps and selective logging, between seasonal leaf loss and permanent deforestation. Investing in a small team of forestry experts for labeling was the single highest-ROI improvement I made.
Lesson 2: Don’t Trust Single-Date Classifications
A single cloud-free image can be misleading. Shadows from clouds outside the image frame, seasonal phenology, and transient events (flooding, fire) can all produce false signals. My production system requires at least two cloud-free observations within a 30-day window before flagging a change event. This reduces false positives by 40% at the cost of some latency in detection.
Lesson 3: Edge Cases Will Kill You
The most common edge cases in satellite imagery forestry:
- Shadows: Mountain shadows look spectrally similar to cloud shadows and can be misclassified as deforestation.
- Wet bare soil: After rain, bare soil has spectral properties similar to degraded forest.
- Mixed pixels: At 10m resolution, a pixel might contain both forest and road, producing misleading spectral signatures.
- Seasonal flooding: Flooded forest looks very different from dry forest but is not deforested.
I handle these with a combination of temporal filtering (require multiple observations), topographic correction (use DEM data to identify shadow-prone areas), and explicit training on these edge cases.
Lesson 4: Build for Retrospective Analysis
Requirements change. A model that classifies “forest vs. non-forest” today might need to distinguish between primary forest, secondary forest, and plantation tomorrow. Store raw detections with confidence scores, not just final classifications. When you retrain your model, you can reprocess historical tiles and compare new detections with old ones without losing the raw signal.
Conclusion
Building production CV pipelines for satellite imagery analysis is a deeply interdisciplinary endeavor. You need expertise in remote sensing (atmospheric correction, spectral analysis), computer vision (model architecture, transfer learning), software engineering (distributed processing, tiling pipelines), and geospatial analysis (PostGIS, coordinate systems, vectorization). No single tool or framework handles all of these well — you need to stitch together a pipeline from specialized components.
The payoff is enormous. A well-built system can monitor millions of hectares of forest in near-real-time, detecting illegal deforestation within days rather than months. For organizations working to protect the world’s forests, this is transformative technology. The key is building it right — with robust preprocessing, domain-appropriate models, and a geospatial database that makes results actionable.