2 releases
| 0.1.1 | Jul 4, 2025 |
|---|---|
| 0.1.0 | Jul 4, 2025 |
#390 in Images
170KB
3.5K
SLoC
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
cargo install glint-mask-tools
From GitHub
cargo install --git https://github.com/tayden/glint-mask-tools-rs.git
From Source
git clone https://github.com/tayden/glint-mask-tools-rs.git
cd glint-mask-tools-rs
cargo build --release
CLI Usage
Process RGB images:
glint-mask rgb input_dir output_dir
Process with custom thresholds:
glint-mask rgb input_dir output_dir --thresholds 0.9,0.8,0.7
Process with pixel buffering:
glint-mask p4ms input_dir output_dir --pixel-buffer 2
List available sensors:
glint-mask list-sensors
Show sensor information:
glint-mask sensor-info rgb
Library Usage
use glint_mask_tools::{
core::masker::MaskerBuilder,
algorithms::ThresholdAlgorithm,
loaders::SingleFileLoader,
sensors::definitions,
};
// Create RGB masker
let rgb_sensor = definitions::rgb_sensor();
let algorithm = ThresholdAlgorithm::new(vec![0.9, 0.8, 0.7])?;
let loader = SingleFileLoader::rgb()?;
let masker = MaskerBuilder::new()
.with_sensor(rgb_sensor)
.with_algorithm(Box::new(algorithm))
.with_loader(Box::new(loader))
.build()?;
// Process images
let stats = masker.process_directory(&input_dir, &output_dir, None)?;
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:
version = "1.0"
[[sensors]]
id = "custom_rgb"
name = "Custom RGB Camera"
description = "RGB camera with custom thresholds"
bit_depth = 8
loader_type = "single_file"
[[sensors.bands]]
name = "Red"
default_threshold = 0.95
wavelength = 650.0
[[sensors.bands]]
name = "Green"
default_threshold = 0.85
wavelength = 560.0
[[sensors.bands]]
name = "Blue"
default_threshold = 0.75
wavelength = 475.0
[sensors.loader_config]
extensions = "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
cargo build
Testing
cargo test
Running Examples
cargo run --example basic_usage
Benchmarks
cargo bench
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.
Dependencies
~21MB
~400K SLoC