Glint Mask Tools (Rust)
A Rust implementation of glint mask generation tools for UAV and aerial imagery. This library detects and masks specular reflections (glint) in imagery from various sensor types.
Features
- Multiple Sensor Support: RGB, CIR, DJI P4MS, DJI M3M, MicaSense RedEdge
- Type-Safe Architecture: Compile-time validation prevents runtime errors
- Extensible Design: Easy to add new sensors and algorithms
- Configuration-Driven: External TOML files for sensor definitions
- Parallel Processing: Multi-threaded processing for performance
- CLI Interface: Command-line tool for processing aerial imagery
- Library API: Programmatic access for integration
Installation
From Cargo
From GitHub
From Source
CLI Usage
Process RGB images:
Process with custom thresholds:
Process with pixel buffering:
List available sensors:
Show sensor information:
Library Usage
use ;
// Create RGB masker
let rgb_sensor = rgb_sensor;
let algorithm = new?;
let loader = rgb?;
let masker = new
.with_sensor
.with_algorithm
.with_loader
.build?;
// Process images
let stats = masker.process_directory?;
Supported Sensors
| Sensor | ID | Bands | Bit Depth | Description |
|---|---|---|---|---|
| RGB Camera | rgb |
3 (R,G,B) | 8-bit | Standard RGB cameras |
| PhaseOne CIR | cir |
4 (R,G,B,NIR) | 8-bit | Color infrared cameras |
| DJI P4MS | p4ms |
5 (B,G,R,RE,NIR) | 16-bit | Phantom 4 Multispectral |
| DJI M3M | m3m |
4 (G,R,RE,NIR) | 16-bit | Mavic 3 Multispectral |
| MicaSense RedEdge | msre |
5 (B,G,R,RE,NIR) | 16-bit | RedEdge multispectral |
| MicaSense RedEdge-MX Dual | msre_dual |
10 (CB,B,G1,G2,R1,R2,RE1,RE2,RE3,NIR) | 16-bit | RedEdge-MX Dual multispectral |
Architecture
The library is built around three main abstractions:
Core Traits
ImageLoader: Handles different sensor file formats (single-file, multi-file, big-tiff)GlintAlgorithm: Implements glint detection algorithms (currently threshold-based)PostProcessor: Processes generated masks (pixel buffering, format conversion)
Key Components
Masker: Main orchestrator that composes loader, algorithm, and post-processorMaskerBuilder: Type-safe builder for constructing processing pipelinesSensorRegistry: Registry system for managing sensor configurationsSensor: Configuration defining bands, thresholds, and loader type
Design Patterns
- Type-Safe Builder: Compile-time validation of component compatibility
- Registry Pattern: Dynamic sensor registration and discovery
- Strategy Pattern: Pluggable loaders for different sensor file formats
- Configuration-Driven: External TOML files for sensor definitions
- Composable Pipeline: Chainable post-processing operations
Processing Flow
- Discovery: Find image captures based on sensor-specific patterns
- Loading: Load single or multi-file captures into normalized arrays
- Normalization: Convert images to [0,1] floating-point range
- Detection: Apply threshold-based glint detection algorithm
- Post-processing: Apply pixel buffering and format conversion
- Output: Save masks in Metashape-compatible format
Module Structure
core/: Core traits and orchestration (masker, sensor registry)algorithms/: Algorithm implementations (threshold detection)loaders/: Loader implementations (single-file, multi-file, big-tiff)config/: Configuration management and sensor definitions
Configuration
Custom Sensor Configuration
You can create custom sensor configurations by editing the sensors.toml file, which is automatically created in your system's configuration directory:
Configuration File Location:
- macOS:
~/Library/Application Support/glint-mask-tools/sensors.toml - Linux:
~/.config/glint-mask-tools/sensors.toml - Windows:
%APPDATA%\glint-mask-tools\sensors.toml
The configuration file is automatically created with default sensor definitions when you first run the tool. You can then modify it to add custom sensors or override existing ones.
Example Custom Sensor Configuration:
= "1.0"
[[]]
= "custom_rgb"
= "Custom RGB Camera"
= "RGB camera with custom thresholds"
= 8
= "single_file"
[[]]
= "Red"
= 0.95
= 650.0
[[]]
= "Green"
= 0.85
= 560.0
[[]]
= "Blue"
= 0.75
= 475.0
[]
= "jpg,jpeg,png,tif,tiff"
After modifying the configuration file, your custom sensors will be available in the CLI. Use glint-mask list-sensors to see all available sensors including your custom ones.
Development
Building
Testing
Running Examples
Benchmarks
Performance
The Rust implementation provides significant performance benefits:
- Memory Safety: Zero-cost abstractions with compile-time safety
- Parallel Processing: Efficient multi-threading with Rayon
- SIMD Operations: Vectorized image processing with ndarray
- Zero-Copy: Efficient memory management for large images
License
MIT License - see LICENSE for details.