Crate tjdistler_iqa

Crate tjdistler_iqa 

Source
Expand description

Fast image quality assessment library

This crate provides implementations of common image quality metrics:

  • SSIM (Structural Similarity Index)
  • MS-SSIM (Multi-Scale SSIM)
  • PSNR (Peak Signal-to-Noise Ratio)
  • MSE (Mean Squared Error)

§Examples

§Basic usage with convenience functions

use tjdistler_iqa::{ssim, psnr, mse, ms_ssim};

let reference = vec![0u8; 256 * 256];
let distorted = vec![0u8; 256 * 256];

let ssim_value = ssim(&reference, &distorted, 256, 256)?;
let psnr_value = psnr(&reference, &distorted, 256, 256)?;
let mse_value = mse(&reference, &distorted, 256, 256)?;
let ms_ssim_value = ms_ssim(&reference, &distorted, 256, 256)?;

§Advanced usage with builders

use tjdistler_iqa::{Ssim, ImageQualityAssessment};

let reference = vec![0u8; 256 * 256];
let distorted = vec![0u8; 256 * 256];

let ssim = Ssim::builder()
    .k1(0.01)
    .k2(0.03)
    .gaussian(true)
    .build();

let result = ssim.assess(&reference, &distorted, 256, 256)?;
println!("SSIM: {}", result.value);

§Model-based repeated comparisons (optimized)

For scenarios where you need to compare multiple distorted images against the same reference, use the pre-computed models for significant performance improvements:

use tjdistler_iqa::{SsimModel, MsSsimModel};

let reference = vec![0u8; 256 * 256];
let distorted1 = vec![0u8; 256 * 256];
let distorted2 = vec![10u8; 256 * 256];
let distorted3 = vec![20u8; 256 * 256];

// Pre-compute reference data once
let ssim_model = SsimModel::new(&reference, 256, 256)?;
let ms_ssim_model = MsSsimModel::new(&reference, 256, 256)?;

// Fast comparisons (40-50% faster than regular functions)
let ssim1 = ssim_model.compare(&distorted1)?;
let ssim2 = ssim_model.compare(&distorted2)?;
let ssim3 = ssim_model.compare(&distorted3)?;

let ms_ssim1 = ms_ssim_model.compare(&distorted1)?;
let ms_ssim2 = ms_ssim_model.compare(&distorted2)?;
let ms_ssim3 = ms_ssim_model.compare(&distorted3)?;

println!("SSIM: {:.4}, {:.4}, {:.4}", ssim1, ssim2, ssim3);
println!("MS-SSIM: {:.4}, {:.4}, {:.4}", ms_ssim1, ms_ssim2, ms_ssim3);

Re-exports§

pub use error::IqaError;
pub use error::Result;
pub use ms_ssim::ms_ssim;
pub use ms_ssim::MsSsim;
pub use ms_ssim::MsSsimBuilder;
pub use ms_ssim_model::MsSsimModel;
pub use ms_ssim_model::MsSsimModelBuilder;
pub use mse::mse;
pub use mse::Mse;
pub use psnr::psnr;
pub use psnr::Psnr;
pub use ssim::ssim;
pub use ssim::Ssim;
pub use ssim::SsimBuilder;
pub use ssim_model::SsimModel;
pub use ssim_model::SsimModelBuilder;

Modules§

error
Error types for image quality assessment operations Error types for image quality assessment operations
ms_ssim
MS-SSIM (Multi-Scale SSIM) implementation
ms_ssim_model
Pre-computed MS-SSIM model for efficient repeated comparisons Pre-computed MS-SSIM model for efficient repeated comparisons
mse
MSE (Mean Squared Error) implementation
psnr
PSNR (Peak Signal-to-Noise Ratio) implementation
ssim
SSIM (Structural Similarity Index) implementation SSIM (Structural Similarity Index) implementation
ssim_model
Pre-computed SSIM model for efficient repeated comparisons Pre-computed SSIM model for efficient repeated comparisons

Structs§

ImageQualityResult
Result of an image quality assessment

Traits§

ImageQualityAssessment
Trait for image quality assessment algorithms