CanopyGIS is an open-source tool for tree-crown polygon delineation from RGB aerial and UAV GeoTIFF imagery without LiDAR. It combines zero-shot concept segmentation from Meta's SAM 3 with shadow-crevice geodesic watershed splitting, region-adjacency-graph (RAG) merging, and planar Voronoi partitioning so every output crown is a non-overlapping, hole-free polygon.
The repository separates two components:
- Standalone zero-shot evaluator (
src/canopygis_v18_eval.py): Pure zero-shotfacebook/sam3plus geodesic watershed, 3-pass RAG merging, and Voronoi planar partitioning. Guaranteesoverlap_px == 0,holes == 0, and single-component topology (Euler == 1), requires zero forestry fine-tuning and zero DeepForest dependency, and runs in< 5 GBpeak GPU VRAM. All MillionTrees benchmark results come solely from this module. - Interactive web app (
src/canopy_v2.py,src/main.py): Local FastAPI UI and static GitHub Pages demo supporting RGB GeoTIFF/UAV uploads (POST /upload), real-time filtering, GeoJSON/CSV export, and optionalWeecology DeepForest 2.1.0nadir treetop seeding. Includes pre-computed Bangkok demo sessions (On Nut, Nong Khaem, and Ramintra Sports Park).
Zero-shot planar crown delineations across the six held-out MillionTrees v0.25 out-of-distribution test sources.
In src/canopygis_v18_eval.py, CanopyGIS prompts facebook/sam3 with three tree-canopy text concepts across full-frame and tiled views, then refines the candidate masks into a clean planar partition:
- Full-frame pass (
post_thr=0.10,mask_thr=0.50, sharing one vision-encoder forward pass across the raw RGB prompts):"tree","individual tree canopy", and"tree canopy"on the raw RGB image."tree"on a CIELAB L-channel shadow-lifted copy of the image.
- Scale-adaptive tiled windows (
post_thr=0.12,mask_thr=0.50):"tree"and"tree canopy"on raw RGB crops."individual tree canopy"on shadow-lifted crops.
- Radiometric shadow lifting: Applies gamma brightening and mild local contrast enhancement only to the CIELAB lightness (
L*) channel while keeping chromaticity (a*,b*) fixed, recovering shaded understory crowns without distorting foliage color. - Shadow-crevice geodesic watershed: Splits large multi-tree canopy clumps along dark inter-crown shadow crevices and crown-dome elevation rather than relying on outer-boundary distance transforms alone.
- 3-pass RAG small-basin merging: Merges over-segmented sub-crown fragments into neighboring basins through a region-adjacency graph unless they are separated by a strong inter-crown shadow crevice.
- Symmetric Voronoi planar partitioning: Resolves overlapping candidate masks by Voronoi distance and enforces single-component, hole-free closure (
overlap_px == 0,holes == 0,Euler == 1) on every predicted crown.
facebook/sam3 is a gated model on Hugging Face; request access on the model card and authenticate (HF_TOKEN or huggingface-cli login) before running inference. Omit [sam3] to install only the CPU geometry utilities.
pip install "canopygis[sam3] @ git+https://github.com/napattan/CanopyGIS.git@v1.8.2"from canopygis_v18_eval import CanopyGISv18Predictor
predictor = CanopyGISv18Predictor.from_pretrained("facebook/sam3", device="cuda")
pred = predictor.predict_tile(img_rgb_uint8, gsd_m=None, score_threshold=0.10)
# pred["y"]: uint8 Tensor[N, H, W] (overlap_px == 0, holes == 0, Euler == 1)git clone https://github.com/napattan/CanopyGIS.git
cd CanopyGIS
pip install -r requirements.txt
cd src && python -m uvicorn main:app --host 127.0.0.1 --port 8000Alternatively, launch with ./start_canopygis.sh (macOS/Linux) or ./start_canopygis.bat (Windows), then open http://127.0.0.1:8000. The UI opens with pre-computed Bangkok demo sessions (On Nut, Nong Khaem, Ramintra) ready to inspect and accepts custom RGB GeoTIFF/UAV uploads via POST /upload.
pytest -v tests/Evaluated with the standalone zero-shot evaluator (src/canopygis_v18_eval.py, score_threshold=0.10, gsd_m=None, zero forestry fine-tuning, zero DeepForest calls, < 5 GB peak GPU VRAM) across all three official MillionTrees v0.25 TreePolygons splits:
| Split | Tiles | MaskRecall | MaskAwareP | F1 | MaskAcc | AP40 | AP60 |
|---|---|---|---|---|---|---|---|
out-of-distribution |
4,133 | 0.617 | 0.936 | 0.744 | 0.314 | 0.439 | 0.350 |
within-distribution |
1,623 | 0.459 | 0.882 | 0.604 | 0.208 | 0.243 | 0.156 |
validation complete-59 |
59 | 0.463 | 0.970 | 0.627 | 0.316 | 0.329 (0.354 macro) | 0.118 (0.160 macro) |
Across all 5,815 tile evaluations (458,851 predicted crowns), every output mask has 0 overlap pixels, 0 holes, and Euler == 1. Full evaluation protocols, baseline comparisons, and per-source breakdowns are documented in docs/CANOPYGIS_EVOLUTION_AND_BENCHMARK_PROTOCOL.md.
If you use CanopyGIS in academic research, please cite it using CITATION.cff:
- Concept DOI (all versions):
10.5281/zenodo.24802070 - Version
v1.8.2DOI:10.5281/zenodo.24802071 - Author: Napat Phasundhiae (ORCID:
0009-0006-4143-3162)
@software{phasundhiae2026canopygis,
author = {Phasundhiae, Napat},
title = {{CanopyGIS}: Zero-Shot Planar Individual Tree Crown Delineation with Euler==1 Topological Closure},
year = {2026},
version = {1.8.2},
doi = {10.5281/zenodo.24802070},
url = {https://github.com/napattan/CanopyGIS}
}CanopyGIS builds on open-source tools and benchmarks from the Weecology Lab (DeepForest, MillionTrees), Meta AI (SAM 3), and OpenGeos (SamGeo).
Released under the MIT License.