Skip to main content

torsh_vision/
lib.rs

1//! Computer vision operations for ToRSh
2//!
3//! This crate provides PyTorch-compatible computer vision functionality including:
4//! - Image transformations and augmentations
5//! - Pre-trained models and model architectures
6//! - Dataset loaders for common vision datasets
7//! - Spatial operations and feature matching
8//! - Video processing capabilities
9//! - 3D visualization utilities
10//!
11//! Built on top of the SciRS2 ecosystem for high-performance image processing.
12//!
13//! # Examples
14//!
15//! ```rust,ignore
16//! use torsh_vision::transforms::*;
17//!
18//! // Create a standard image transformation pipeline
19//! let transform = Compose::new(vec![
20//!     Box::new(Resize::new((224, 224))),
21//!     Box::new(ToTensor::new()),
22//!     Box::new(Normalize::new(vec![0.485, 0.456, 0.406], vec![0.229, 0.224, 0.225])),
23//! ]);
24//! ```
25
26#![allow(clippy::all)]
27#![allow(dead_code)]
28#![allow(unused_imports)]
29#![allow(ambiguous_glob_reexports)]
30
31pub mod advanced_transforms;
32pub mod benchmarks;
33pub mod datasets;
34pub mod datasets_impl;
35pub mod error_handling;
36pub mod examples;
37pub mod explainability;
38pub mod feature_detection_advanced;
39pub mod hardware;
40pub mod interactive;
41pub mod io;
42pub mod memory;
43pub mod models;
44pub mod ops;
45pub mod optimized_impl;
46pub mod prelude;
47pub mod scirs2_integration;
48pub mod segmentation_advanced;
49pub mod self_supervised;
50pub mod spatial;
51pub mod streaming;
52pub mod transforms;
53pub mod unified_transforms;
54pub mod utils;
55pub mod video;
56pub mod viz3d;
57
58pub use advanced_transforms::*;
59pub use datasets::{DatasetConfig, DatasetError, DatasetStats};
60pub use datasets_impl::{CifarDataset, CocoDataset, ImageFolder, MnistDataset, VocDataset};
61pub use error_handling::*;
62pub use examples::*;
63pub use explainability::{
64    AttentionVisualizer, BaselineType, FeatureVisualizer, GradCAM, IntegratedGradients, SaliencyMap,
65};
66pub use hardware::*;
67pub use interactive::*;
68pub use io::*;
69pub use memory::*;
70pub use models::*;
71pub use ops::{
72    adjust_brightness, adjust_contrast, adjust_hue, adjust_saturation, calculate_iou, center_crop,
73    edge_detection, gaussian_blur, generate_anchors, histogram_equalization, horizontal_flip,
74    morphological_operation, nms, normalize, random_crop, resize, rgb_to_grayscale, rotate,
75    sobel_edge_detection, vertical_flip,
76};
77pub use spatial::{
78    distance::PatchMatcher,
79    interpolation::{ImageWarper, OpticalFlowInterpolator, SpatialInterpolator},
80    matching::{Feature, FeatureMatcher, Keypoint, TemplateMatcher},
81    structures::{BoundingBox, PointCloudProcessor, SpatialObjectTracker},
82    transforms::{GeometricProcessor, ImageRegistrar, PoseEstimator},
83    FeatureMatch, SpatialConfig, SpatialPoint, SpatialProcessor, TransformResult,
84};
85pub use transforms::*;
86pub use unified_transforms::*;
87pub use utils::*;
88pub use video::*;
89pub use viz3d::*;
90
91// Comprehensive scirs2-vision integration
92pub use scirs2_integration::{
93    ContrastMethod, CornerPoint, DenoiseMethod, DisparityMap, EdgeDetectionMethod,
94    Keypoint as SciKeypoint, MemoryStrategy, OpticalFlow, OrbFeatures, QualityLevel,
95    SciRS2VisionProcessor, SiftFeatures, SimdLevel, SurfFeatures, VisionConfig,
96};
97
98// Self-supervised learning augmentations
99pub use self_supervised::{
100    BYOLAugmentation, DINOAugmentation, GaussianBlur, MoCoAugmentation, RandomGrayscale,
101    SimCLRAugmentation, Solarize, SwAVAugmentation,
102};
103
104// Advanced segmentation algorithms (NEW in 0.1.5 integration)
105pub use segmentation_advanced::{
106    graph_cuts, region_growing, watershed, Connectivity, GraphCutsConfig, RegionGrowingConfig,
107    WatershedConfig, WatershedMarkers,
108};
109
110// Advanced feature detection and matching (NEW in 0.1.5 integration)
111pub use feature_detection_advanced::{
112    apply_ratio_test, AttentionMatcher, AttentionMatcherConfig, BruteForceMatcher, DistanceMetric,
113    Feature as AdvancedFeature, FeatureMatch as AdvancedFeatureMatch, LearnedSiftConfig,
114    LearnedSiftDetector, MultiScaleConfig, MultiScaleDetector, SuperPointConfig,
115    SuperPointDetector,
116};
117
118// Real-time streaming and performance (NEW in 0.1.5 integration)
119pub use streaming::{
120    BatchProcessor, Frame, FrameMetadata, FramePreprocessor, QualityAdaptation, StreamConfig,
121    StreamProcessor, StreamStats,
122};
123
124// Comprehensive benchmarking suite
125pub use benchmarks::{
126    run_full_benchmark_suite, run_quick_benchmark, AccuracyMetrics, BenchmarkConfig,
127    BenchmarkResult, VisionBenchmarkSuite,
128};
129
130// Version information
131pub const VERSION: &str = env!("CARGO_PKG_VERSION");
132pub const VERSION_MAJOR: u32 = 0;
133pub const VERSION_MINOR: u32 = 1;
134pub const VERSION_PATCH: u32 = 0;
135
136#[derive(Debug, thiserror::Error)]
137pub enum VisionError {
138    #[error("Image processing error: {0}")]
139    ImageError(#[from] image::ImageError),
140
141    #[error("Model error: {0}")]
142    ModelError(String),
143
144    #[error("Transform error: {0}")]
145    TransformError(String),
146
147    #[error("Invalid shape: {0}")]
148    InvalidShape(String),
149
150    #[error("Invalid argument: {0}")]
151    InvalidArgument(String),
152
153    #[error("Invalid input: {0}")]
154    InvalidInput(String),
155
156    #[error("Invalid parameter: {0}")]
157    InvalidParameter(String),
158
159    #[error("IO error: {0}")]
160    IoError(#[from] std::io::Error),
161
162    #[error("Tensor error: {0}")]
163    TensorError(#[from] torsh_core::error::TorshError),
164
165    #[cfg(feature = "pretrained")]
166    #[error("Request error: {0}")]
167    RequestError(#[from] reqwest::Error),
168
169    #[error("Other error: {0}")]
170    Other(#[from] anyhow::Error),
171}
172
173pub type Result<T> = std::result::Result<T, VisionError>;
174
175// Conversion from VisionError to TorshError for Module trait compatibility
176impl From<VisionError> for torsh_core::error::TorshError {
177    fn from(err: VisionError) -> Self {
178        torsh_core::error::TorshError::Other(err.to_string())
179    }
180}