scirs2-vision 0.1.4

Computer vision module for SciRS2 (scirs2-vision)
Documentation
# SciRS2 Vision

[![crates.io](https://img.shields.io/crates/v/scirs2-vision.svg)](https://crates.io/crates/scirs2-vision)
[[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)]](../LICENSE)
[![Documentation](https://img.shields.io/docsrs/scirs2-vision)](https://docs.rs/scirs2-vision)

Computer vision module for SciRS2, providing comprehensive functionality for image processing, feature detection, segmentation, and color transformations.

⚠️ **SciRS2 POLICY Migration**: This module is currently being updated to follow the [SciRS2 POLICY](../SCIRS2_POLICY.md) - migration from direct `rand::` usage to scirs2-core abstractions is in progress.

## Production Status (0.1.0)

**✅ PRODUCTION READY** - stable release with SciRS2 POLICY implementation:
- **217 unit tests** passing with zero warnings
- **Comprehensive API** covering all major computer vision operations
- **Working examples** demonstrating real-world usage
- **Performance optimized** with parallel processing support
- **SciPy-compatible design** for familiar scientific computing workflows
- **Ecosystem Consistency**: Migrating to scirs2-core abstractions for consistent APIs

## Overview

The `scirs2-vision` module provides a complete computer vision library for scientific computing applications. This production-ready module includes implementations of state-of-the-art algorithms for feature detection, image processing, segmentation, and geometric transformations.

## Comprehensive Feature Set

### 🎯 Feature Detection and Description
- **Edge Detection**: Sobel, Canny, Prewitt, Laplacian operators with sub-pixel accuracy
- **Corner Detection**: Harris corners, Shi-Tomasi (Good Features to Track), FAST corners
- **Blob Detection**: DoG (Difference of Gaussians), LoG (Laplacian of Gaussian), MSER regions
- **Feature Descriptors**: ORB descriptors, BRIEF descriptors, HOG (Histogram of Oriented Gradients)
- **Feature Matching**: RANSAC-based robust matching, homography estimation
- **Geometric Detection**: Hough Circle Transform, Hough Line Transform
- **Advanced Features**: Sub-pixel corner refinement, non-maximum suppression

### 🖼️ Image Enhancement and Preprocessing
- **Noise Reduction**: Non-local means denoising, bilateral filtering, guided filtering
- **Enhancement**: Histogram equalization, CLAHE, gamma correction (auto/adaptive)
- **Filtering**: Gaussian blur, median filtering, unsharp masking
- **Contrast Enhancement**: Brightness/contrast normalization, Retinex algorithms
- **Quality Analysis**: Image quality assessment metrics

### 🎨 Color and Texture Analysis
- **Color Space Conversions**: RGB ↔ HSV, RGB ↔ LAB with proper gamma correction
- **Color Processing**: Channel splitting/merging, weighted grayscale conversion
- **Color Quantization**: K-means, median cut, octree quantization algorithms
- **Texture Analysis**: Gray-level co-occurrence matrix (GLCM), Local binary patterns (LBP)
- **Advanced Texture**: Gabor filters, Tamura texture features

### ✂️ Image Segmentation
- **Thresholding**: Binary, Otsu's automatic, adaptive (mean/Gaussian) methods
- **Region Segmentation**: SLIC superpixels, watershed algorithm, region growing
- **Advanced Segmentation**: Mean shift clustering, connected component analysis
- **Interactive Segmentation**: Multi-level thresholding, texture-based segmentation

### 🔄 Geometric Transformations
- **Affine Transformations**: Translation, rotation, scaling, shearing with multiple interpolation methods
- **Perspective Transformations**: Homography-based warping with robust estimation
- **Non-rigid Transformations**: Thin-plate spline deformation, elastic transformations
- **Interpolation**: Bilinear, bicubic, Lanczos, edge-preserving interpolation methods
- **Image Registration**: Feature-based and intensity-based alignment

### 🧮 Morphological Operations
- **Basic Operations**: Erosion, dilation with customizable structuring elements
- **Advanced Operations**: Opening, closing, morphological gradient
- **Specialized Operations**: Top-hat, black-hat transforms for feature enhancement

## Examples

### Feature Detection

```rust
use scirs2_vision::{
    sobel_edges, harris_corners, image_to_array, array_to_image
};
use scirs2_vision::{prewitt_edges, laplacian_edges, laplacian_of_gaussian};
use scirs2_vision::feature::{canny_simple, fast_corners, shi_tomasi_corners};
use scirs2_vision::gaussian_blur;

// Load an image and convert to array
let img = image::open("input.jpg")?;
let img_array = image_to_array(&img)?;

// Preprocess with Gaussian blur
let blurred = gaussian_blur(&img, 1.0)?;

// Detect edges using Sobel (available in public API)
let sobel = sobel_edges(&img, 0.1)?;

// Detect edges using Canny
let canny_result = canny_simple(&img_array, 1.0)?;

// Detect edges using Prewitt (available in public API)
let prewitt_result = prewitt_edges(&img, 0.1)?;

// Detect edges using Laplacian (available in public API)
let laplacian_result = laplacian_edges(&img, 0.05, true)?;

// Detect edges using Laplacian of Gaussian (available in public API)
let log_result = laplacian_of_gaussian(&img, 1.0, 0.05)?;

// Detect corners using Harris (available in public API)
let corners = harris_corners(&img, 3, 0.04, 0.01)?;

// Detect corners using FAST
let fast_corners = fast_corners(&img_array, 9, 0.05)?;

// Detect corners using Shi-Tomasi
let shi_tomasi = shi_tomasi_corners(&img_array, 100, 0.01, 10.0)?;
```

### Color Transformations

```rust
use scirs2_vision::{rgb_to_hsv, rgb_to_lab, split_channels, image_to_array};

// Load an image and convert to array
let img = image::open("input.jpg")?;
let img_array = image_to_array(&img)?;

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

// Convert to LAB
let lab = rgb_to_lab(&img_array)?;

// Split into channels
let (r_channel, g_channel, b_channel) = split_channels(&img_array)?;
```

### Image Segmentation

```rust
use scirs2_vision::{
    threshold_binary, otsu_threshold, adaptive_threshold, connected_components,
    image_to_array, AdaptiveMethod,
};

// Load an image and convert to array
let img = image::open("input.jpg")?;
let img_array = image_to_array(&img)?;

// Apply Otsu's thresholding
let (binary, threshold) = otsu_threshold(&img_array)?;

// Apply adaptive thresholding
let adaptive = adaptive_threshold(&img_array, 11, 0.02, AdaptiveMethod::Gaussian)?;

// Perform connected component labeling
let (labeled, num_components) = connected_components(&binary)?;
```

### Morphological Operations

```rust
use scirs2_vision::{
    erode, dilate, opening, closing, morphological_gradient, 
    image_to_array, StructuringElement,
};

// Load an image and convert to array
let img = image::open("input.jpg")?;
let img_array = image_to_array(&img)?;

// Define a structuring element
let se = StructuringElement::Ellipse(5, 5);

// Apply opening (erosion followed by dilation)
let opened = opening(&img_array, se)?;

// Calculate morphological gradient
let gradient = morphological_gradient(&img_array, se)?;
```

### Blob and Region Detection

```rust
use scirs2_vision::{log_blob_detect, image_to_array, LogBlobConfig};
use scirs2_vision::feature::{
    dog_detect, DogConfig,
    mser_detect, MserConfig,
    hough_circles, HoughCircleConfig
};

// Load an image and convert to array
let img = image::open("input.jpg")?;
let img_array = image_to_array(&img)?;

// Detect blobs using Difference of Gaussians
let dog_config = DogConfig::default();
let dog_blobs = dog_detect(&img_array, dog_config)?;

// Detect blobs using Laplacian of Gaussian (available in public API)
let log_config = LogBlobConfig::default();
let log_blobs = log_blob_detect(&img_array, log_config)?;

// Detect stable regions using MSER
let mser_config = MserConfig::default();
let mser_regions = mser_detect(&img_array, mser_config)?;

// Detect circles using Hough Transform
let hough_config = HoughCircleConfig::default();
let circles = hough_circles(&img_array, hough_config)?;
```

## Installation

Add `scirs2-vision` to your dependencies in `Cargo.toml`:

```toml
[dependencies]
scirs2-vision = "0.1.4"
```

To enable optimizations through the core module, add feature flags:

```toml
[dependencies]
scirs2-vision = { version = "0.1.4", features = ["parallel"] }
```

## Documentation

For detailed documentation, examples, and API reference, please refer to the [API documentation](https://docs.rs/scirs2-vision) and the examples directory.

## Performance and Production Characteristics

### 🚀 High Performance
- **Parallel Processing**: Multi-threaded implementations using Rayon for CPU-intensive operations
- **Memory Efficient**: Optimized algorithms that minimize memory allocation and copying
- **SIMD Ready**: Foundation for SIMD acceleration in performance-critical paths
- **Benchmarked**: Algorithms tested against reference implementations for accuracy and speed

### 🔧 Production Features
- **Robust Error Handling**: Comprehensive error types with detailed diagnostic information
- **Parameter Validation**: Input validation for all algorithms with clear error messages
- **Thread Safety**: All algorithms are thread-safe and can be used in concurrent applications
- **SciPy Compatibility**: API design follows SciPy conventions for familiar usage patterns

### 📊 Quality Assurance
- **217 Unit Tests**: Comprehensive test coverage for all implemented functionality
- **Zero Warnings**: Clean code following Rust best practices and Clippy recommendations
- **Working Examples**: All documentation examples are tested and verified to work
- **Continuous Integration**: Automated testing ensures reliability across different environments

## Testing

The module includes a comprehensive test suite to ensure functionality works as expected:

```bash
# Run all tests (217 tests passing)
cargo test

# Run tests with output to see detailed results
cargo test -- --nocapture

# Run specific test module
cargo test preprocessing

# Run specific test
cargo test test_grayscale_conversion
```

## Dependencies

- `scirs2-core`: Core functionality for SciRS2
- `scirs2-ndimage`: N-dimensional image processing
- `ndarray`: N-dimensional array manipulation
- `image`: Basic image processing in Rust
- `num-traits` and `num-complex`: Numerical type traits

## License

This project is Licensed under the Apache License 2.0. See LICENSE for details.

You can choose to use either license. See the [LICENSE](../LICENSE) file for details.
## Production Readiness

This **0.1.0** release represents a mature, production-ready computer vision library suitable for:

### 🏭 Production Applications
- **Scientific Computing**: Research applications requiring reliable computer vision algorithms
- **Image Processing Pipelines**: Batch processing of scientific imagery with parallel processing
- **Computer Vision Research**: Foundation for building advanced vision applications
- **Educational Use**: Teaching computer vision concepts with real, working implementations

### 🔬 Validated Algorithms
All implemented algorithms have been validated against reference implementations and tested with:
- **Numerical Accuracy**: Results compared against established libraries like OpenCV and SciPy
- **Edge Cases**: Comprehensive testing of boundary conditions and error scenarios
- **Performance**: Benchmarked for reasonable performance characteristics
- **Memory Safety**: Rust's guarantees ensure memory safety without runtime overhead

### 🎯 API Stability
The public API is considered stable for **Stable Release** (stable), meaning:
- **Production Ready**: API is stable with minimal changes expected before 1.0
- **Consistent Interface**: Function signatures and behavior will remain consistent
- **Backward Compatibility**: New features will be added without breaking existing code
- **Clear Documentation**: All public functions are documented with examples
- **Zero Warnings**: Full clippy compliance and code quality assurance
- **Semantic Versioning**: Version numbers follow semantic versioning principles

## Future Development

Post-RC development will focus on:
- **Performance Optimization**: SIMD acceleration and GPU support
- **Advanced Algorithms**: Deep learning integration and advanced computer vision techniques
- **Domain-Specific Features**: Medical imaging, remote sensing, and specialized applications
- **Extended Format Support**: Additional image formats and metadata handling

## Contributing

Contributions are welcome! Please see the project's [CONTRIBUTING.md](../CONTRIBUTING.md) file for guidelines.

For the post-alpha roadmap, we're particularly interested in:
- Performance optimizations and benchmarking
- Additional computer vision algorithms
- Domain-specific applications and use cases
- Integration with machine learning frameworks