pub struct Zensim { /* private fields */ }Expand description
Metric configuration. Methods on this struct are the primary API.
use zensim::{Zensim, ZensimProfile, RgbSlice};
let z = Zensim::new(ZensimProfile::latest());
let source = RgbSlice::new(&src, 8, 8);
let distorted = RgbSlice::new(&dst, 8, 8);
let result = z.compute(&source, &distorted).unwrap();
println!("{}: {:.2}", result.profile(), result.score());Implementations§
Source§impl Zensim
impl Zensim
Sourcepub fn compute_with_ref_and_diffmap(
&self,
precomputed: &PrecomputedReference,
distorted: &impl ImageSource,
options: impl Into<DiffmapOptions>,
) -> Result<DiffmapResult, ZensimError>
pub fn compute_with_ref_and_diffmap( &self, precomputed: &PrecomputedReference, distorted: &impl ImageSource, options: impl Into<DiffmapOptions>, ) -> Result<DiffmapResult, ZensimError>
Compare with precomputed reference and return both score and per-pixel error map.
The diffmap fuses SSIM error maps from all pyramid scales, weighted by the profile’s trained weights. Coarser scales are upsampled to full resolution and blended. The zensim score uses the identical multi-scale pipeline.
§Use case
Encoder quantization loops: precompute the reference once, then in each iteration call this to get both a global quality score (for convergence) and a spatial error map (for per-block quant field adjustment).
§Errors
Returns ZensimError::ImageTooSmall if dimensions < 8×8.
Sourcepub fn compute_with_ref_and_diffmap_linear_planar(
&self,
precomputed: &PrecomputedReference,
planes: [&[f32]; 3],
width: usize,
height: usize,
stride: usize,
options: impl Into<DiffmapOptions>,
) -> Result<DiffmapResult, ZensimError>
pub fn compute_with_ref_and_diffmap_linear_planar( &self, precomputed: &PrecomputedReference, planes: [&[f32]; 3], width: usize, height: usize, stride: usize, options: impl Into<DiffmapOptions>, ) -> Result<DiffmapResult, ZensimError>
Compare planar linear RGB f32 against a precomputed reference, producing both a score and a per-pixel error map.
planes are [R, G, B], each with at least stride * height elements.
stride is the number of f32 elements per row (≥ width).
This avoids the interleave-to-RGBA overhead when the caller already has separate channel buffers in linear light (e.g., from an encoder’s reconstruction pipeline).
§Errors
Returns ZensimError::ImageTooSmall if dimensions < 8×8.
Sourcepub fn compute_with_diffmap(
&self,
source: &impl ImageSource,
distorted: &impl ImageSource,
options: impl Into<DiffmapOptions>,
) -> Result<DiffmapResult, ZensimError>
pub fn compute_with_diffmap( &self, source: &impl ImageSource, distorted: &impl ImageSource, options: impl Into<DiffmapOptions>, ) -> Result<DiffmapResult, ZensimError>
Compare two images and return both score and per-pixel error map.
Convenience method that handles precomputation internally.
For iterative use (encoder loops), prefer precompute_reference +
compute_with_ref_and_diffmap to avoid re-converting the reference each time.
§Errors
Returns ZensimError if dimensions are mismatched or too small.
Source§impl Zensim
impl Zensim
Sourcepub fn new(profile: ZensimProfile) -> Self
pub fn new(profile: ZensimProfile) -> Self
Create a new Zensim with the given profile. Parallel by default.
Sourcepub fn with_parallel(self, parallel: bool) -> Self
pub fn with_parallel(self, parallel: bool) -> Self
Enable or disable multi-threaded computation (rayon).
Default: true.
Sourcepub fn profile(&self) -> ZensimProfile
pub fn profile(&self) -> ZensimProfile
Current profile.
Sourcepub fn compute(
&self,
source: &impl ImageSource,
distorted: &impl ImageSource,
) -> Result<ZensimResult, ZensimError>
pub fn compute( &self, source: &impl ImageSource, distorted: &impl ImageSource, ) -> Result<ZensimResult, ZensimError>
Compare source and distorted images.
§Errors
Returns ZensimError if dimensions are mismatched or too small.
Sourcepub fn precompute_reference(
&self,
source: &impl ImageSource,
) -> Result<PrecomputedReference, ZensimError>
pub fn precompute_reference( &self, source: &impl ImageSource, ) -> Result<PrecomputedReference, ZensimError>
Pre-compute reference image data for batch comparison.
§Errors
Returns ZensimError::ImageTooSmall if dimensions < 8×8.
Sourcepub fn compute_with_ref(
&self,
precomputed: &PrecomputedReference,
distorted: &impl ImageSource,
) -> Result<ZensimResult, ZensimError>
pub fn compute_with_ref( &self, precomputed: &PrecomputedReference, distorted: &impl ImageSource, ) -> Result<ZensimResult, ZensimError>
Compare a distorted image against a precomputed reference.
§Errors
Returns ZensimError::ImageTooSmall if dimensions < 8×8.
Sourcepub fn precompute_reference_linear_planar(
&self,
planes: [&[f32]; 3],
width: usize,
height: usize,
stride: usize,
) -> Result<PrecomputedReference, ZensimError>
pub fn precompute_reference_linear_planar( &self, planes: [&[f32]; 3], width: usize, height: usize, stride: usize, ) -> Result<PrecomputedReference, ZensimError>
Precompute reference from planar linear RGB f32 data.
planes are [R, G, B], each with at least stride * height elements.
stride is the number of f32 elements per row (≥ width; may be larger
for padded buffers like the encoder’s padded_width).
This avoids the interleave-to-RGBA overhead when the caller already has separate channel buffers in linear light.
§Errors
Returns ZensimError::ImageTooSmall if dimensions < 8×8.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Zensim
impl RefUnwindSafe for Zensim
impl Send for Zensim
impl Sync for Zensim
impl Unpin for Zensim
impl UnsafeUnpin for Zensim
impl UnwindSafe for Zensim
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more