| Crates.io | tjdistler-iqa |
| lib.rs | tjdistler-iqa |
| version | 1.2.0 |
| created_at | 2025-08-03 01:36:56.337282+00 |
| updated_at | 2025-08-04 09:30:24.879518+00 |
| description | Fast image quality assessment library (SSIM, MS-SSIM, PSNR, MSE) ported from Tom Distler's C implementation |
| homepage | https://github.com/ideamans/rust-tjdistler-iqa |
| repository | https://github.com/ideamans/rust-tjdistler-iqa |
| max_upload_size | |
| id | 1779277 |
| size | 1,066,679 |
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.
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 |
Add this to your Cargo.toml:
[dependencies]
tjdistler-iqa = "1.2.0"
use tjdistler_iqa::{ssim, psnr, mse, ms_ssim};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load your images (grayscale, 8-bit)
let width = 256;
let height = 256;
let reference = vec![0u8; width * height];
let distorted = vec![0u8; width * height];
// Calculate metrics
let ssim_value = ssim(&reference, &distorted, width, height)?;
let psnr_value = psnr(&reference, &distorted, width, height)?;
let mse_value = mse(&reference, &distorted, width, height)?;
let ms_ssim_value = ms_ssim(&reference, &distorted, width, height)?;
println!("SSIM: {}", ssim_value);
println!("PSNR: {} dB", psnr_value);
println!("MSE: {}", mse_value);
println!("MS-SSIM: {}", ms_ssim_value);
Ok(())
}
use tjdistler_iqa::{Ssim, ImageQualityAssessment};
let ssim = Ssim::builder()
.k1(0.01) // Default: 0.01
.k2(0.03) // Default: 0.03
.gaussian(true) // Default: true (Gaussian window)
.scale(2) // Default: auto-calculated
.build();
let result = ssim.assess(&reference, &distorted, width, height)?;
println!("Custom SSIM: {}", result.value);
use tjdistler_iqa::{MsSsim, ImageQualityAssessment};
let ms_ssim = MsSsim::builder()
.gaussian(true) // Use Gaussian window
.scales(5) // Number of scales
.build();
let result = ms_ssim.assess(&reference, &distorted, width, height)?;
println!("Custom MS-SSIM: {}", result.value);
For scenarios where you need to compare multiple images against the same reference image, use the computation model API for significant performance improvements:
use tjdistler_iqa::{SsimModel, MsSsimModel};
// Create models with pre-computed reference image data
let ssim_model = SsimModel::new(&reference, width, height)?;
let ms_ssim_model = MsSsimModel::new(&reference, width, height)?;
// Compare multiple images efficiently
for distorted_image in &distorted_images {
let ssim_score = ssim_model.compare(distorted_image)?;
let ms_ssim_score = ms_ssim_model.compare(distorted_image)?;
println!("SSIM: {}, MS-SSIM: {}", ssim_score, ms_ssim_score);
}
Performance improvements for batch processing:
Measures the structural similarity between two images. Values range from -1 to 1, where 1 indicates perfect similarity.
An extension of SSIM that operates on multiple scales, making it more robust to viewing distance variations.
Measures the ratio between the maximum possible signal power and corrupting noise power. Higher values (in dB) indicate better quality.
Calculates the average squared difference between pixels. Lower values indicate better quality (0 means identical images).
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 demonstrationRun examples with:
cargo run --example basic
cargo run --example custom_ssim
cargo run --example model_demo
# Clone the repository
git clone https://github.com/ideamans/rust-tjdistler-iqa.git
cd rust-tjdistler-iqa
# Build
cargo build --release
# Run tests
cargo test
# Run benchmarks (requires C library for comparison)
make benchmark
This crate requires Rust 1.70.0 or later.
BSD 3-Clause License. See LICENSE for details.
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/
Contributions are welcome! Please feel free to submit a Pull Request.
Before contributing:
cargo fmt to format your codecargo clippy to check for common issuescargo test