Skip to main content

Crate scirs2_vision

Crate scirs2_vision 

Source
Expand description

Β§SciRS2 Computer Vision

scirs2-vision provides comprehensive computer vision and image processing capabilities built on SciRS2’s scientific computing infrastructure, offering torchvision/OpenCV-compatible APIs with Rust’s performance and safety.

§🎯 Key Features

  • Feature Detection: SIFT, ORB, Harris corners, LoG blob detection
  • Image Segmentation: Watershed, region growing, graph cuts, semantic segmentation
  • Edge Detection: Sobel, Canny, Prewitt, Laplacian
  • Image Registration: Homography, affine, perspective transformations
  • Color Processing: Color space conversions, histogram operations
  • Advanced Processing: Super-resolution, HDR, denoising
  • Object Tracking: DeepSORT, Kalman filtering
  • Performance: SIMD acceleration, parallel processing, GPU support

Β§πŸ“¦ Module Overview

ModuleDescriptionPython Equivalent
featureFeature detection and matching (SIFT, ORB, Harris)OpenCV features2d
segmentationImage segmentation algorithmsscikit-image.segmentation
preprocessingImage filtering and enhancementtorchvision.transforms
colorColor space conversionsOpenCV color
transformGeometric transformationstorchvision.transforms
registrationImage registration and alignmentscikit-image.registration
streamingReal-time video processingOpenCV VideoCapture

Β§πŸš€ Quick Start

Β§Installation

Add to your Cargo.toml:

[dependencies]
scirs2-vision = "0.1.5"

Β§Feature Detection (Harris Corners)

use scirs2_vision::harris_corners;
use image::open;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load image
    let img = open("image.jpg")?;

    // Detect Harris corners
    let corners = harris_corners(&img, 3, 0.04, 100.0)?;
    println!("Detected Harris corners");

    Ok(())
}

Β§SIFT Feature Detection

use scirs2_vision::detect_and_compute;
use image::open;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let img = open("image.jpg")?;

    // Detect SIFT keypoints and compute descriptors
    let descriptors = detect_and_compute(&img, 500, 0.03)?;
    println!("Detected {} SIFT features", descriptors.len());

    Ok(())
}

Β§Edge Detection (Sobel)

use scirs2_vision::sobel_edges;
use image::open;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let img = open("image.jpg")?;

    // Detect edges using Sobel operator
    let edges = sobel_edges(&img, 0.1)?;
    println!("Edge map computed");

    Ok(())
}

Β§Image Segmentation (Watershed)

use scirs2_vision::watershed;
use image::open;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let img = open("image.jpg")?;

    // Perform watershed segmentation
    let segments = watershed(&img, None, 8)?;
    println!("Segmented into regions");

    Ok(())
}

Β§Color Space Conversion

use scirs2_vision::{rgb_to_grayscale, rgb_to_hsv};
use image::open;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let img = open("image.jpg")?;

    // Convert to grayscale
    let gray = rgb_to_grayscale(&img, None)?;

    // Convert to HSV
    let hsv = rgb_to_hsv(&img)?;

    Ok(())
}

Β§Image Registration (Homography)

use scirs2_vision::find_homography;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Source and destination points
    let src_points = vec![(0.0, 0.0), (100.0, 0.0), (100.0, 100.0), (0.0, 100.0)];
    let dst_points = vec![(10.0, 10.0), (110.0, 5.0), (105.0, 105.0), (5.0, 110.0)];

    // Find homography matrix
    let (_h, _inliers) = find_homography(&src_points, &dst_points, 3.0, 0.99)?;

    // Warp image using homography
    // let warped = warp_perspective(&img, &h, (width, height))?;

    Ok(())
}

Β§Super-Resolution

use scirs2_vision::{SuperResolutionProcessor, SuperResolutionMethod};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let processor = SuperResolutionProcessor::new(
        2, // scale factor
        SuperResolutionMethod::ESRCNN
    )?;

    // Upscale image
    // let upscaled = processor.process(&low_res_image)?;

    Ok(())
}

Β§Object Tracking (DeepSORT)

use scirs2_vision::{DeepSORT, Detection, TrackingBoundingBox};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut tracker = DeepSORT::new();

    // For each frame
    let bbox = TrackingBoundingBox::new(10.0, 10.0, 50.0, 50.0, 0.9, 0);
    let detections = vec![Detection::new(bbox)];

    let tracks = tracker.update(detections)?;
    for track in tracks {
        println!("Track ID: {}, Position: {:?}", track.id, track.get_bbox());
    }

    Ok(())
}

§🧠 Feature Detection Methods

Β§Classical Features

  • Harris Corners: Fast corner detection algorithm
  • SIFT: Scale-Invariant Feature Transform (rotation and scale invariant)
  • ORB: Oriented FAST and Rotated BRIEF (efficient alternative to SIFT)
  • LoG Blobs: Laplacian of Gaussian blob detection

Β§Neural Features

  • SuperPoint: Learned keypoint detector and descriptor
  • Learned SIFT: Neural network-enhanced SIFT

Β§Feature Matching

  • Brute-force matching: Exhaustive descriptor comparison
  • Neural matching: Attention-based feature matching

§🎨 Segmentation Methods

Β§Classical Segmentation

  • Watershed: Marker-based segmentation
  • Region Growing: Similarity-based region merging
  • Graph Cuts: Energy minimization segmentation
  • Threshold: Otsu, adaptive thresholding

Β§Advanced Segmentation

  • Semantic Segmentation: Deep learning-based pixel classification
  • Instance Segmentation: Object detection + segmentation

Β§πŸš„ Performance

scirs2-vision leverages multiple optimization strategies:

  • SIMD: Vectorized operations for pixel processing
  • Parallel: Multi-threaded execution for large images
  • GPU: CUDA/OpenCL support for accelerated operations
  • Memory Efficient: Zero-copy views, chunked processing

Β§Thread Safety

All functions are thread-safe and can be called concurrently on different images. When the parallel feature is enabled, many algorithms automatically utilize multiple CPU cores:

  • Gradient computations in edge detection
  • Pixel-wise operations in preprocessing
  • Feature detection across image regions
  • Segmentation clustering steps

Note: Mutable image data should not be shared between threads without proper synchronization.

Β§πŸ“Š Comparison with Other Libraries

FeatureOpenCVtorchvisionscirs2-vision
Feature Detectionβœ…βŒβœ…
Segmentationβœ…βš οΈ (limited)βœ…
Geometric Transformsβœ…βœ…βœ…
GPU Supportβœ…βœ…βœ… (limited)
Type SafetyβŒβŒβœ…
Memory SafetyβŒβš οΈβœ…
Pure RustβŒβŒβœ…

Β§πŸ”— Integration with SciRS2 Ecosystem

  • scirs2-ndimage: Low-level image operations
  • scirs2-linalg: Matrix operations for geometric transforms
  • scirs2-neural: Deep learning models for advanced tasks
  • scirs2-stats: Statistical analysis of image features
  • scirs2-cluster: Clustering for segmentation

Β§πŸ”’ Version

Current version: 0.1.5 (Released January 15, 2026)

Re-exportsΒ§

pub use error::Result;
pub use error::VisionError;
pub use detection::batched_nms;
pub use detection::clip_boxes;
pub use detection::compute_ap;
pub use detection::compute_map;
pub use detection::filter_by_confidence;
pub use detection::generate_anchors;
pub use detection::generate_ssd_anchors;
pub use detection::generate_yolo_anchors;
pub use detection::nms;
pub use detection::precision_recall_curve;
pub use detection::random_crop_with_boxes;
pub use detection::random_horizontal_flip;
pub use detection::scale_boxes;
pub use detection::soft_nms;
pub use detection::translate_boxes;
pub use detection::weighted_nms;
pub use detection::AnchorConfig;
pub use detection::DetectionBox;
pub use feature::array_to_image;
pub use feature::calc_optical_flow;
pub use feature::compute_descriptors;
pub use feature::corners::CornerDetectParams;
pub use feature::corners::CornerMethod;
pub use feature::corners::CornerPoint;
pub use feature::descriptor::detect_and_compute;
pub use feature::descriptor::match_descriptors;
pub use feature::descriptor::Descriptor;
pub use feature::descriptor::KeyPoint;
pub use feature::descriptors::DescriptorMethod;
pub use feature::descriptors::DescriptorParams;
pub use feature::descriptors::UnifiedDescriptor;
pub use feature::detect_corners;
pub use feature::find_homography;
pub use feature::flow_unified::FlowMethod;
pub use feature::flow_unified::FlowResult;
pub use feature::harris_corners;
pub use feature::horn_schunck_flow;
pub use feature::image_to_array;
pub use feature::laplacian::laplacian_edges;
pub use feature::laplacian::laplacian_of_gaussian;
pub use feature::log_blob::log_blob_detect;
pub use feature::log_blob::log_blobs_to_image;
pub use feature::log_blob::LogBlob;
pub use feature::log_blob::LogBlobConfig;
pub use feature::match_unified_descriptors;
pub use feature::orb::detect_and_compute_orb;
pub use feature::orb::match_orb_descriptors;
pub use feature::orb::OrbConfig;
pub use feature::orb::OrbDescriptor;
pub use feature::prewitt::prewitt_edges;
pub use feature::sobel::sobel_edges_simd;
pub use feature::sobel_edges;
pub use feature::AdvancedDenoiser;
pub use feature::AppearanceExtractor;
pub use feature::AttentionFeatureMatcher;
pub use feature::DeepSORT;
pub use feature::DenoisingMethod;
pub use feature::Detection;
pub use feature::HDRProcessor;
pub use feature::HornSchunckParams;
pub use feature::KalmanFilter;
pub use feature::LearnedSIFT;
pub use feature::NeuralFeatureConfig;
pub use feature::NeuralFeatureMatcher;
pub use feature::SIFTConfig;
pub use feature::SuperPointNet;
pub use feature::SuperResolutionMethod;
pub use feature::SuperResolutionProcessor;
pub use feature::ToneMappingMethod;
pub use feature::Track;
pub use feature::TrackState;
pub use feature::TrackingBoundingBox;
pub use feature::TrackingMetrics;
pub use feature::homography::warp_perspective as feature_warp_perspective;
pub use enhancement::contrast_stretch_auto;
pub use enhancement::contrast_stretch_linear;
pub use enhancement::contrast_stretch_log;
pub use enhancement::contrast_stretch_power;
pub use enhancement::homomorphic_filter;
pub use geometric::affine_transform as geometric_affine_transform;
pub use geometric::crop;
pub use geometric::flip_horizontal;
pub use geometric::flip_vertical;
pub use geometric::pad;
pub use geometric::perspective_transform as geometric_perspective_transform;
pub use geometric::resize as geometric_resize;
pub use geometric::rotate;
pub use geometric::Interpolation;
pub use geometric::PadMode;
pub use histogram::backproject_histogram;
pub use histogram::backproject_hs_histogram;
pub use histogram::binarize_otsu;
pub use histogram::clahe as histogram_clahe;
pub use histogram::compute_cdf;
pub use histogram::compute_color_histogram;
pub use histogram::compute_histogram;
pub use histogram::equalize_histogram as histogram_equalize;
pub use histogram::equalize_histogram_color;
pub use histogram::match_histogram;
pub use histogram::match_histogram_image;
pub use histogram::multi_otsu_threshold;
pub use histogram::otsu_threshold;
pub use histogram::otsu_threshold_from_histogram;
pub use histogram::ColorHistogram;
pub use histogram::Histogram;
pub use transform::affine::estimate_affine_transform;
pub use transform::affine::warp_affine;
pub use transform::affine::AffineTransform;
pub use transform::affine::BorderMode;
pub use transform::non_rigid::warp_elastic;
pub use transform::non_rigid::warp_non_rigid;
pub use transform::non_rigid::warp_thin_plate_spline;
pub use transform::non_rigid::ElasticDeformation;
pub use transform::non_rigid::ThinPlateSpline;
pub use transform::perspective::correct_perspective;
pub use transform::perspective::BorderMode as PerspectiveBorderMode;
pub use transform::perspective::PerspectiveTransform;
pub use transform::perspective::warp_perspective as transform_warp_perspective;
pub use simd_ops::check_simd_support;
pub use simd_ops::simd_convolve_2d;
pub use simd_ops::simd_gaussian_blur;
pub use simd_ops::simd_histogram_equalization;
pub use simd_ops::simd_normalize_image;
pub use simd_ops::simd_sobel_gradients;
pub use simd_ops::SimdPerformanceStats;
pub use gpu_ops::gpu_batch_process;
pub use gpu_ops::gpu_convolve_2d;
pub use gpu_ops::gpu_gaussian_blur;
pub use gpu_ops::gpu_harris_corners;
pub use gpu_ops::gpu_sobel_gradients;
pub use gpu_ops::GpuBenchmark;
pub use gpu_ops::GpuMemoryStats;
pub use gpu_ops::GpuVisionContext;
pub use streaming::AdvancedStreamPipeline;
pub use streaming::AdvancedStreamProcessor;
pub use streaming::BlurStage;
pub use streaming::EdgeDetectionStage;
pub use streaming::Frame;
pub use streaming::FrameMetadata;
pub use streaming::GrayscaleStage;
pub use streaming::PipelineMetrics;
pub use streaming::ProcessingStage;
pub use streaming::SimplePerformanceMonitor;
pub use streaming::StreamPipeline;
pub use streaming::StreamProcessor;
pub use streaming::VideoStreamReader;
pub use quantum_inspired_streaming::ProcessingDecision;
pub use quantum_inspired_streaming::QuantumAdaptiveStreamPipeline;
pub use quantum_inspired_streaming::QuantumAmplitude;
pub use quantum_inspired_streaming::QuantumAnnealingStage;
pub use quantum_inspired_streaming::QuantumEntanglementStage;
pub use quantum_inspired_streaming::QuantumProcessingState;
pub use quantum_inspired_streaming::QuantumStreamProcessor;
pub use quantum_inspired_streaming::QuantumSuperpositionStage;
pub use neuromorphic_streaming::AdaptiveNeuromorphicPipeline;
pub use neuromorphic_streaming::EfficiencyMetrics;
pub use neuromorphic_streaming::EventDrivenProcessor;
pub use neuromorphic_streaming::EventStats;
pub use neuromorphic_streaming::NeuromorphicEdgeDetector;
pub use neuromorphic_streaming::NeuromorphicMode;
pub use neuromorphic_streaming::NeuromorphicProcessingStats;
pub use neuromorphic_streaming::PlasticSynapse;
pub use neuromorphic_streaming::SpikingNeuralNetwork;
pub use neuromorphic_streaming::SpikingNeuron;
pub use ai_optimization::ArchitecturePerformance;
pub use ai_optimization::GeneticPipelineOptimizer;
pub use ai_optimization::NeuralArchitectureSearch;
pub use ai_optimization::PerformanceMetric;
pub use ai_optimization::PipelineGenome;
pub use ai_optimization::PredictiveScaler;
pub use ai_optimization::ProcessingArchitecture;
pub use ai_optimization::RLParameterOptimizer;
pub use ai_optimization::ScalingRecommendation;
pub use ai_optimization::SearchStrategy;
pub use scene_understanding::analyze_scene_with_reasoning;
pub use scene_understanding::ContextualReasoningEngine;
pub use scene_understanding::DetectedObject as SceneObject;
pub use scene_understanding::SceneAnalysisResult;
pub use scene_understanding::SceneGraph;
pub use scene_understanding::SceneUnderstandingEngine;
pub use scene_understanding::SpatialRelation;
pub use scene_understanding::SpatialRelationType;
pub use scene_understanding::TemporalInfo;
pub use visual_reasoning::perform_advanced_visual_reasoning;
pub use visual_reasoning::QueryType;
pub use visual_reasoning::ReasoningAnswer;
pub use visual_reasoning::ReasoningStep;
pub use visual_reasoning::UncertaintyQuantification;
pub use visual_reasoning::VisualReasoningEngine;
pub use visual_reasoning::VisualReasoningQuery;
pub use visual_reasoning::VisualReasoningResult;
pub use activity_recognition::monitor_activities_realtime;
pub use activity_recognition::recognize_activities_comprehensive;
pub use activity_recognition::ActivityRecognitionEngine;
pub use activity_recognition::ActivityRecognitionResult;
pub use activity_recognition::ActivitySequence;
pub use activity_recognition::ActivitySummary as ActivitySceneSummary;
pub use activity_recognition::DetectedActivity;
pub use activity_recognition::MotionCharacteristics;
pub use activity_recognition::PersonInteraction;
pub use activity_recognition::TemporalActivityModeler;
pub use visual_slam::process_visual_slam;
pub use visual_slam::process_visual_slam_realtime;
pub use visual_slam::CameraPose;
pub use visual_slam::CameraTrajectory;
pub use visual_slam::LoopClosure;
pub use visual_slam::Map3D;
pub use visual_slam::SLAMResult;
pub use visual_slam::SLAMSystemState;
pub use visual_slam::SemanticMap;
pub use visual_slam::VisualSLAMSystem;
pub use vision_3d::stereo_bm;
pub use vision_3d::stereo_sgbm;
pub use vision_3d::structure_from_motion;
pub use vision_3d::triangulate_points;
pub use vision_3d::BMParams;
pub use vision_3d::DisparityMap;
pub use vision_3d::PointCloud;
pub use vision_3d::SGBMParams;
pub use vision_3d::SfMResult;
pub use vision_3d::StereoAlgorithm;
pub use integration::batch_process_advanced;
pub use integration::process_with_advanced_mode;
pub use integration::realtime_advanced_stream;
pub use integration::AdvancedProcessingResult;
pub use integration::CrossModuleAdvancedProcessingResult;
pub use integration::EmergentBehaviorDetection;
pub use integration::FusionQualityIndicators;
pub use integration::NeuralQuantumHybridProcessor;
pub use integration::PerformanceMetrics;
pub use integration::UncertaintyQuantification as AdvancedUncertaintyQuantification;
pub use performance_benchmark::AdvancedBenchmarkSuite;
pub use performance_benchmark::BenchmarkConfig;
pub use performance_benchmark::BenchmarkResult;
pub use performance_benchmark::ComparisonMetrics;
pub use performance_benchmark::PerformanceMetrics as BenchmarkPerformanceMetrics;
pub use performance_benchmark::QualityMetrics;
pub use performance_benchmark::ResourceUsage;
pub use performance_benchmark::ScalabilityMetrics;
pub use performance_benchmark::StatisticalSummary;
pub use video::adaptive_learning_rate;
pub use video::block_match_full;
pub use video::block_match_tss;
pub use video::mask_to_binary;
pub use video::motion_compensate;
pub use video::phase_correlation;
pub use video::prediction_error;
pub use video::smooth_trajectory;
pub use video::stabilisation_corrections;
pub use video::BackgroundConfig;
pub use video::ForegroundLabel;
pub use video::GmmBackground;
pub use video::MedianBackground;
pub use video::MotionField;
pub use video::MotionVector;
pub use video::RunningAverageBackground;
pub use video::ShadowParams;
pub use video::apply_translation;
pub use video::double_frame_difference;
pub use video::frame_difference;
pub use video::interpolate_linear;
pub use video::interpolate_motion_compensated;
pub use video::threshold_difference;
pub use video::TemporalGaussianFilter;
pub use video::TemporalMedianFilter;
pub use video::tracking::BBox as VideoBBox;
pub use video::tracking::CamShiftTracker;
pub use video::tracking::KalmanModel as VideoKalmanModel;
pub use video::tracking::KalmanTracker as VideoKalmanTracker;
pub use video::tracking::MeanShiftConfig;
pub use video::tracking::MeanShiftTracker;
pub use video::tracking::MultiObjectTracker;
pub use video::tracking::MultiTrackerConfig;
pub use video::tracking::TrackStatus as VideoTrackStatus;
pub use video::tracking::TrackedObject;
pub use segmentation::*;
pub use preprocessing::*;
pub use color::*;

ModulesΒ§

_transform
Private transform module for compatibility
activity_recognition
Advanced Activity Recognition Framework
ai_optimization
AI-based optimization for computer vision pipelines
calibration
Camera calibration algorithms
camera
Camera models for 3D vision
camera_model
Camera models for 3D vision
color
Color transformation module
depth
Depth estimation algorithms.
depth_estimation
Monocular depth estimation features
depth_processing
Depth Image Processing
descriptors
Feature descriptor algorithms.
detection
Object detection utilities
enhancement
Image enhancement algorithms
error
Error types for the vision module
face_detection
Face detection algorithms.
feature
Feature detection and extraction module
feature_extraction
Classical image feature extraction
features
SIFT-like and ORB-like feature detection, binary/float matching, and robust homography estimation.
geometric
Geometric image transformations
gpu_ops
GPU-accelerated operations for computer vision
histogram
Histogram operations for image analysis
image_quality
Image quality assessment metrics (ndarray API)
instance_segmentation
Instance segmentation algorithms
integration
Advanced Integration - Cross-Module AI Coordination
matching
Descriptor matching algorithms.
medical
Medical imaging utilities for scirs2-vision
morphology
Morphological image operations (ndarray API)
neuromorphic_streaming
Neuromorphic streaming processing for brain-inspired computer vision
object_detection
Generic Object Detection Utilities
optical_flow_dense
Dense optical flow algorithms.
performance_benchmark
Advanced Performance Benchmarking for Advanced Mode
point_cloud
3D Point Cloud Processing
pointcloud
3-D Point Cloud Processing.
pose
Pose estimation and camera geometry.
preprocessing
Image preprocessing functionality
quality
Image quality assessment metrics
quantum_inspired_streaming
Quantum-inspired streaming processing for next-generation computer vision
reconstruction
3D Reconstruction algorithms
registration
Image registration algorithms
scene_understanding
Advanced Scene Understanding Framework
segmentation
Image segmentation module
semantic_segmentation
Semantic segmentation algorithms
simd_ops
SIMD-accelerated operations for computer vision
slam
Visual SLAM components
stereo
Stereo vision and depth estimation.
stereo_legacy
Stereo vision algorithms
stitch
Image stitching utilities
streaming
Streaming processing pipeline for video and real-time image processing
style_transfer
Neural style transfer utilities
transform
Image transformation module
video
Video and temporal processing algorithms.
video_processing
Video frame buffer and temporal processing utilities.
video_stabilization
Video stabilisation algorithms.
vision_3d
3D Vision module - Stereo vision, depth estimation, and structure from motion
visual_reasoning
Advanced Visual Reasoning Framework
visual_slam
Advanced Visual SLAM Framework

MacrosΒ§

recover_or_fallback
Macro for automatic error recovery in vision operations