glint-mask-tools 0.1.1

Rust implementation of glint mask generation tools for UAV and aerial imagery
Documentation
/// Basic usage example for the glint mask generation library.
///
/// This example demonstrates how to use the library programmatically
/// to generate glint masks from UAV imagery.
use glint_mask_tools::{
    algorithms::ThresholdAlgorithm,
    core::{
        masker::MaskerBuilder,
        postprocessor::{CompositePostProcessor, MetashapeConverter, PixelBufferProcessor},
        sensor::SensorRegistry,
    },
    error::Result,
    loaders::SingleFileLoader,
};
use std::path::PathBuf;

fn main() -> Result<()> {
    // Initialize logging
    tracing_subscriber::fmt::init();

    // Set up paths
    let input_dir = PathBuf::from("input_images");
    let output_dir = PathBuf::from("output_masks");

    // Get RGB sensor configuration from registry
    // This will load from user config if available, otherwise fall back to defaults
    let registry = SensorRegistry::from_user_config();
    let rgb_sensor = registry.get_sensor("rgb").unwrap().clone();

    // Create threshold algorithm with custom thresholds
    let thresholds = vec![0.9, 0.8, 0.7]; // R, G, B
    let algorithm = ThresholdAlgorithm::new(thresholds)?;

    // Create post-processing pipeline
    let postprocessor = CompositePostProcessor::new()
        .add_processor(Box::new(PixelBufferProcessor::new(2))) // 2-pixel buffer
        .add_processor(Box::new(MetashapeConverter::new())); // Convert to Metashape format

    // Create RGB image loader
    let loader = SingleFileLoader::rgb()?;

    // Build the masker
    let masker = MaskerBuilder::new()
        .with_sensor(rgb_sensor)
        .with_algorithm(Box::new(algorithm))
        .with_postprocessor(Box::new(postprocessor))
        .with_loader(Box::new(loader))
        .build()?;

    // Process images
    println!("Processing RGB images...");
    let stats = masker.process_directory(&input_dir, &output_dir, None)?;

    // Report results
    println!("Processing complete!");
    println!("Total captures: {}", stats.total_captures);
    println!("Successful: {}", stats.successful_captures);
    println!("Failed: {}", stats.failed_captures);
    println!("Success rate: {:.1}%", stats.success_rate());

    if !stats.all_successful() {
        eprintln!("Some captures failed to process");
        for error in &stats.errors {
            eprintln!("  Error: {}", error);
        }
    }

    Ok(())
}