SciRS2 NDImage
scirs2-ndimage is the N-dimensional image processing crate for the SciRS2 scientific computing library. It provides a comprehensive toolkit for filtering, morphology, interpolation, measurements, segmentation, and feature detection on arrays of arbitrary dimensionality, modeled after SciPy's ndimage module.
What scirs2-ndimage Provides
Use scirs2-ndimage when you need to:
- Filter N-dimensional arrays (Gaussian, median, rank, bilateral, edge detection)
- Apply morphological operations to binary or grayscale images in any dimension
- Measure region properties (area, centroid, moments, Hu moments) after labeling
- Segment images with watershed, active contours, or graph cut methods
- Transform arrays geometrically (rotate, zoom, shift, affine transform)
- Analyze 3D volumetric data (medical images, electron microscopy)
- Process hyperspectral imagery
- Compute co-occurrence matrices and texture features
- Detect features (corners, edges, SIFT descriptors, HOG)
- Perform atlas-based segmentation
Features (v0.3.4)
Image Filtering
- Gaussian Filters:
gaussian_filter,gaussian_filter1d,gaussian_gradient_magnitude,gaussian_laplace - Median Filter: N-dimensional median filter with configurable footprint
- Rank Filters: Minimum, maximum, percentile, generic rank filter (full n-dimensional support)
- Edge Detection: Sobel, Prewitt, Laplacian, Scharr, Roberts cross-gradient
- Bilateral Filter: Edge-preserving bilateral filtering
- Uniform Filter: Box/uniform convolution filter
- Generic Filter: Apply any custom function over a sliding window
- Convolution: N-dimensional
convolveandconvolve1d - Boundary Modes:
reflect,nearest,wrap,mirror,constant - Fourier Filters: Fourier Gaussian, uniform, ellipsoid, shift operations
Morphological Operations
- Binary Morphology: Erosion, dilation, opening, closing, hit-or-miss transform, propagation, hole filling
- Grayscale Morphology: Erosion, dilation, opening, closing, top-hat (white/black), morphological gradient, Laplace
- Distance Transforms: Euclidean (EDT via Felzenszwalb-Huttenlocher O(n) algorithm), city-block, chessboard
- Connected Components: Labeling, find objects, remove small objects
- Structuring Elements: Generate disk, square, diamond, and arbitrary structuring elements
- Skeletonization: Topological thinning to medial axis
Image Measurements
- Region Statistics: Sum, mean, variance, standard deviation, min, max per label
- Moments: Raw moments, central moments, normalized moments, Hu moments (rotation-invariant)
- Region Properties: Area, perimeter, centroid, bounding box, eccentricity, orientation, principal axes
- Center of Mass: N-dimensional center of mass computation
- Extrema: Local and global minima/maxima with positions
- Histograms: Per-label histogram computation
- Inertia Tensor: Region inertia tensor for orientation analysis
Image Segmentation
- Thresholding: Binary, Otsu's automatic, adaptive (mean/Gaussian)
- Watershed: Standard watershed and marker-controlled watershed
- Active Contours: Snakes with gradient vector flow (GVF)
- Level Set Methods: Chan-Vese segmentation (single and multi-phase)
- Graph Cuts: Max-flow/min-cut segmentation with interactive refinement
- SLIC Superpixels: Simple Linear Iterative Clustering (2D and 3D)
- Atlas-Based Segmentation: Label transfer via registration atlas
Feature Detection
- Edge Detection: Canny edge detector, unified edge detection API
- Corner Detection: Harris corners, FAST corners
- SIFT Descriptor Computation: Scale-space keypoint detection and description
- HOG (Histogram of Oriented Gradients): Cell-based gradient histogram features
- Template Matching: Normalized cross-correlation, zero-mean NCC
- Gabor Filters: 2D Gabor filter bank for texture analysis
- Shape Analysis: Moments-based shape descriptors, shape matching
Geometric Interpolation
- Map Coordinates: Interpolate array at arbitrary coordinates (0th-5th order splines)
- Affine Transform: Apply an affine transformation matrix
- Geometric Transform: General geometric transformation with custom mapping
- Shift: Sub-pixel shift with spline interpolation
- Rotate: Array rotation about any axis
- Zoom: Uniform and anisotropic zooming
- Spline Filter: Pre-filter for spline interpolation (
spline_filter,spline_filter1d)
3D Volume Analysis
- Volumetric Operations: 3D morphology, filtering, distance transforms
- 3D Filters: 3D Gaussian, Sobel, Laplacian, bilateral
- Volume Measurements: 3D region properties, surface area, Euler characteristic
- Slice Processing: Per-slice operations on 3D stacks
Medical Image Processing
- Frangi Vesselness: Multi-scale vessel enhancement filter
- Bone Enhancement: Bone structure enhancement for CT data
- Lung Nodule Detection: Basic nodule candidate generation
- DICOM-Compatible Arrays: Works natively with 3D medical arrays
Hyperspectral Image Analysis
- Band Processing: Per-band filtering and morphology
- Spectral Indices: NDVI, NDWI, and custom spectral index computation
- Spectral Unmixing: Linear unmixing of spectral signatures
- Cloud Detection: Cloud and shadow masking for satellite imagery
- Pan-Sharpening: Fusion of panchromatic and multispectral bands
Co-occurrence Matrices and Texture
- GLCM: Gray-level co-occurrence matrix computation (2D and 3D)
- Texture Features: Contrast, correlation, energy, homogeneity from GLCM
- LBP: Local binary patterns
- Gabor Feature Maps: Multi-scale multi-orientation Gabor responses
Deep Feature Extraction Interface
- Interface for forwarding arrays through external feature extractors
- Hooks for deep learning model integration (via scirs2-neural)
Installation
[]
= "0.3.4"
For parallel processing and SIMD:
[]
= { = "0.3.4", = ["parallel", "simd"] }
Feature Flags
| Flag | Description |
|---|---|
parallel |
Enable Rayon-based multi-core parallel processing (recommended for arrays >10K elements) |
simd |
Enable SIMD vectorization for filters and morphological operations |
Quick Start
use ;
use Array2;
Comprehensive Examples
Filtering
use filters;
use Array2;
Morphological Operations
use morphology;
use Array2;
Region Measurements
use ;
use Array2;
Watershed Segmentation
use watershed;
use filters;
use Array2;
3D Volume Processing
use filters;
use Array3;
SLIC Superpixels
use slic_superpixels;
use Array3;
Atlas-Based Segmentation
use atlas_based_segment;
use CoreResult;
Performance
- SIMD acceleration: 2-4x speedup on supported filter and morphology operations
- Parallel processing: Linear scaling with CPU cores for large arrays (
parallelfeature) - O(n) distance transform: Felzenszwalb-Huttenlocher separable EDT algorithm
- Memory-efficient: Chunked processing for images larger than available RAM
- N-dimensional: Consistent API and performance across 1D, 2D, 3D, and higher dimensions
Compatibility with SciPy ndimage
API is modeled after scipy.ndimage. Key equivalents:
| SciRS2 | SciPy |
|---|---|
filters::gaussian_filter() |
scipy.ndimage.gaussian_filter() |
filters::median_filter() |
scipy.ndimage.median_filter() |
filters::sobel() |
scipy.ndimage.sobel() |
morphology::binary_erosion() |
scipy.ndimage.binary_erosion() |
morphology::distance_transform_edt() |
scipy.ndimage.distance_transform_edt() |
measurements::label() |
scipy.ndimage.label() |
measurements::center_of_mass() |
scipy.ndimage.center_of_mass() |
interpolation::affine_transform() |
scipy.ndimage.affine_transform() |
interpolation::map_coordinates() |
scipy.ndimage.map_coordinates() |
interpolation::rotate() |
scipy.ndimage.rotate() |
interpolation::zoom() |
scipy.ndimage.zoom() |
Documentation
Full API reference: docs.rs/scirs2-ndimage
License
Licensed under the Apache License 2.0. See LICENSE for details.