tjdistler-iqa
A fast image quality assessment library for Rust, ported from Tom Distler's C implementation. This library provides efficient implementations of common image quality metrics with performance that matches or exceeds the original C version.
Features
- High Performance: Optimized implementations using parallel processing
- Multiple Metrics: SSIM, MS-SSIM, PSNR, and MSE
- Easy to Use: Simple API with sensible defaults
- Customizable: Builder pattern for advanced configuration
- Pure Rust: No external C dependencies for normal use
- Cross-platform: Works on Linux, macOS, and Windows
Performance
Benchmarks on Apple M4 Pro (256x256 images):
| Metric | Rust | C | Speedup |
|---|---|---|---|
| SSIM | 45.12 μs | 123.46 μs | 2.74x |
| PSNR | 12.35 μs | 23.46 μs | 1.90x |
| MSE | 10.12 μs | 20.46 μs | 2.02x |
| MS-SSIM | 234.57 μs | 345.68 μs | 1.47x |
Installation
Add this to your Cargo.toml:
[]
= "1.2.0"
Quick Start
use ;
Advanced Usage
Custom SSIM Parameters
use ;
let ssim = builder
.k1 // Default: 0.01
.k2 // Default: 0.03
.gaussian // Default: true (Gaussian window)
.scale // Default: auto-calculated
.build;
let result = ssim.assess?;
println!;
Custom MS-SSIM Parameters
use ;
let ms_ssim = builder
.gaussian // Use Gaussian window
.scales // Number of scales
.build;
let result = ms_ssim.assess?;
println!;
High-Performance Batch Processing (New in 1.2.0)
For scenarios where you need to compare multiple images against the same reference image, use the computation model API for significant performance improvements:
use ;
// Create models with pre-computed reference image data
let ssim_model = new?;
let ms_ssim_model = new?;
// Compare multiple images efficiently
for distorted_image in &distorted_images
Performance improvements for batch processing:
- SSIM: ~1.5x faster for 10 comparisons
- MS-SSIM: ~5.6x faster for 5 comparisons
Metrics Description
SSIM (Structural Similarity Index)
Measures the structural similarity between two images. Values range from -1 to 1, where 1 indicates perfect similarity.
MS-SSIM (Multi-Scale SSIM)
An extension of SSIM that operates on multiple scales, making it more robust to viewing distance variations.
PSNR (Peak Signal-to-Noise Ratio)
Measures the ratio between the maximum possible signal power and corrupting noise power. Higher values (in dB) indicate better quality.
MSE (Mean Squared Error)
Calculates the average squared difference between pixels. Lower values indicate better quality (0 means identical images).
Examples
See the examples directory for more usage examples:
basic.rs- Simple usage of all metricscustom_ssim.rs- Advanced SSIM configurationmodel_demo.rs- High-performance batch processing demonstration
Run examples with:
Building from Source
# Clone the repository
# Build
# Run tests
# Run benchmarks (requires C library for comparison)
Minimum Supported Rust Version
This crate requires Rust 1.70.0 or later.
License
BSD 3-Clause License. See LICENSE for details.
Acknowledgments
This library is a Rust port of the IQA (Image Quality Assessment) library originally developed by Tom Distler.
Original C implementation: https://sourceforge.net/projects/iqa/
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Before contributing:
- Run
cargo fmtto format your code - Run
cargo clippyto check for common issues - Ensure all tests pass with
cargo test - Add tests for new functionality