Data and code from: Leveraging foundation models and time-lapse photography for semi-automated tracking of tree apical growth
Data files
Abstract
Primary height growth of tree seedlings strongly influences survival, competition, forest structure, and productivity, yet high-resolution, in situ measurements of intra-seasonal apical growth are rare due to labor constraints. This study presents a semi-automated image-analysis framework that integrates: Time-lapse field photography; The Segment Anything Model v2 (SAM2) foundation segmentation model; and Skeleton-based length extraction methods to quantify fine-scale leader elongation through time. The framework was applied to 105 balsam fir (Abies balsamea) leaders at two field sites in Québec, Canada, across 13 growing seasons, producing high-frequency time series of apical growth derived from image segmentation and validated against manual measurements. This repository enables reproducibility, method evaluation, and reuse of both the image data and the semi-automated processing workflow.
This repository contains the data and code used in the study:
“Leveraging Foundation Models and Time-Lapse Photography for Semi-Automated Tracking of Tree Apical Growth”
🌲 Project Overview
Primary height growth determines tree seedling survival, competition, forest structure, and productivity. However, efficient in-situ methods to track fine-scale height growth over time are lacking.
This project introduces a semi-automated framework that combines:
- Time-lapse photography
- The Segment Anything Model v2 (SAM2)
- Skeleton-based length measurement
to quantify intra-seasonal conifer apical growth.
The method was applied to 105 balsam fir leaders from two sites in Québec, Canada, spanning 13 growing seasons.
📁 Repository Structure
Data.zip/
├── AnnualROICroppedDailyImages/ # Cropped time-series images
├── VideoSAM/ # empty folder for SAM2 outputs (frames, prompts, masks, results)
├── Measurements/ # Manual reference measurements in XLSX and CSV format (code uses XLSX files)
├── AblationSensAnalysis/ # Results of ablation sensitivity analysis (9792 configurations)
Code.zip/
└── LengthTracker.py # Main processing script
⚙️ What the Code Does
LengthTracker.py performs the full workflow:
- Manual input
- Draw bounding boxes around leaders (every 5 frames)
- Select the transition between early (bud/whorl) and late (leader extension) growth phases
- Automated processing
- Propagate segmentations through time using SAM2
- Clean masks (noise removal, region filtering)
- Measure leader length using skeleton-based curved path extraction
- Detect and interpolate outliers
- Apply seven-day rolling median window smoothing
- Output
- Daily leader length (pixels)
- Percent of seasonal maximum growth
- Comparison with manual measurements stored in annual XLSX files in "Measurements" folder
- CSV files for each leader
💻 System Requirements
This workflow requires a CUDA-enabled GPU.
Tested with:
- Python 3.10+
- PyTorch with CUDA
- SAM2 (Meta AI Research)
📦 Dependencies
Install SAM2 following the official instructions:
https://github.com/facebookresearch/sam2
Additional Python packages used:
numpy
pandas
opencv-python
torch
torchvision
matplotlib
scikit-image
networkx
scipy
statsmodels
openpyxl
Pillow
🚀 How to Run
Step 1 — Install SAM2
Follow the official installation guide from Meta AI Research (https://github.com/facebookresearch/sam2).
Step 2 — Set Model Paths
In LengthTracker.py, update:
sam2_checkpoint = "/path/to/sam2.1_hiera_large.pt"
model_cfg = "/path/to/sam2.1_hiera_l.yaml"
Step 3 — Organize Data
Ensure the directory structure matches:
Data/AnnualROICroppedDailyImages/{site}/{leader_ID}/
Step 4 — Run the Script
python Code/LengthTracker.py
✋ Manual Steps Required
The workflow is semi-automated. Users must:
- Draw a box around the leader every 5 frames
- Select the start of Phase 2 (apical dominance)
These prompts are saved and then used for segmentation.
📤 Outputs
For each leader:
VideoSAM/{site}/{leader_ID}/Results/
└── leader_{ID}_manual_vs_sam_lengths.csv
Contains:
- Manual leader length (px)
- SAM vertical length (px)
- SAM curved length (px)
- Percent seasonal growth
📊 Validation Summary
- SAM2 lengths closely matched manual measurements (R2 = 0.98)
- Semi-automated workflow was ~20× faster than manual measurement
📜 Citation
If you use this code or data, please cite:
Spafford et al., Leveraging Foundation Models and Time-Lapse Photography for Semi-Automated Tracking of Tree Apical Growth, [Ecological Informatics, 2026]
