### Install DSSIM as System Library (Linux) Source: https://context7.com/kornelski/dssim/llms.txt Installs the DSSIM library system-wide on Linux, making it available via `pkg-config`. Requires `cargo-c` to be installed. ```bash # Install as system library (Linux) cargo install cargo-c cargo cinstall --release --destdir=/ --prefix=/usr/lib # Installs libdssim.so and makes 'dssim' available to pkg-config ``` -------------------------------- ### Install DSSIM-core Library System-Wide (Linux) Source: https://github.com/kornelski/dssim/blob/main/dssim-core/README.md Installs the dssim shared library (`.so`) and headers system-wide on Linux using `cargo-c`. This makes the library available via `pkg-config`. ```bash cargo install cargo-c cargo cinstall --release --destdir=/ --prefix=/usr/lib ``` -------------------------------- ### Build DSSIM Core Library for C Integration Source: https://github.com/kornelski/dssim/blob/main/README.md Steps to build the dssim-core library as a static archive (`.a`) for use in C projects. Includes instructions for both manual building and using `cargo-c` for system-wide installation. ```bash cd dssim-core rustup update cargo build --release ``` ```bash cargo install cargo-c cargo cinstall --release --destdir=/ --prefix=/usr/lib ``` -------------------------------- ### DSSIM C API Example Source: https://context7.com/kornelski/dssim/llms.txt Demonstrates how to use the DSSIM C API to compare two RGBA images. Ensure you link against the `dssim_core` static library. ```c #include "dssim.h" #include #include int main() { // Create comparison context Dssim *dssim = dssim_new(); // Example: 64x64 red and slightly different red images uint32_t width = 64, height = 64; size_t pixel_count = width * height * 4; // RGBA uint8_t *pixels1 = malloc(pixel_count); uint8_t *pixels2 = malloc(pixel_count); // Fill with test data (RGBA format) for (size_t i = 0; i < width * height; i++) { pixels1[i*4 + 0] = 200; // R pixels1[i*4 + 1] = 100; // G pixels1[i*4 + 2] = 50; // B pixels1[i*4 + 3] = 255; // A pixels2[i*4 + 0] = 205; // Slightly different R pixels2[i*4 + 1] = 100; pixels2[i*4 + 2] = 50; pixels2[i*4 + 3] = 255; } // Create preprocessed images DssimImage *img1 = dssim_create_image_rgba(dssim, pixels1, width, height); DssimImage *img2 = dssim_create_image_rgba(dssim, pixels2, width, height); if (img1 && img2) { // Compare images double score = dssim_compare(dssim, img1, img2); printf("DSSIM score: %.6f\n", score); // Clean up images dssim_free_image(img1); dssim_free_image(img2); } // Clean up context dssim_free(dssim); free(pixels1); free(pixels2); return 0; } // Compile with: // gcc -o dssim_example example.c -L./target/release -ldssim_core -lpthread -lm ``` -------------------------------- ### Complete Image Comparison in Rust Source: https://context7.com/kornelski/dssim/llms.txt This example demonstrates loading two images, performing a DSSIM comparison, and interpreting the resulting score and SSIM maps. Ensure you have the `dssim-core`, `imgref`, and `rgb` crates added to your `Cargo.toml`. ```rust use dssim_core::{Dssim, ToRGBAPLU, SsimMap}; use imgref::Img; use rgb::RGBA; fn compare_images() -> Result<(), Box> { // Create comparison context let mut dssim = Dssim::new(); // Enable SSIM map generation for visualization dssim.set_save_ssim_maps(1); // Simulate loading images (in practice, use lodepng or image crate) let width = 100; let height = 100; // Original image: gradient let original: Vec> = (0..width*height) .map(|i| { let x = (i % width) as u8; let y = (i / width) as u8; RGBA { r: x, g: y, b: 128, a: 255 } }) .collect(); // Modified image: same gradient with noise let modified: Vec> = original.iter() .enumerate() .map(|(i, px)| { let noise = ((i * 7) % 10) as u8; RGBA { r: px.r.saturating_add(noise), g: px.g, b: px.b, a: px.a } }) .collect(); // Convert to linear light and create DSSIM images let img1 = dssim.create_image(&Img::new(original.to_rgbaplu(), width, height)) .ok_or("Failed to create image 1")?; let img2 = dssim.create_image(&Img::new(modified.to_rgbaplu(), width, height)) .ok_or("Failed to create image 2")?; // Run comparison let (score, ssim_maps) = dssim.compare(&img1, &img2); // Interpret results println!("DSSIM Score: {:.6}", score); println!("Interpretation:"); if score < 0.0001 { println!(" Images are virtually identical"); } else if score < 0.001 { println!(" Differences barely perceptible"); } else if score < 0.01 { println!(" Minor but noticeable differences"); } else if score < 0.1 { println!(" Significant differences"); } else { println!(" Images are very different"); } // Analyze SSIM maps if available if let Some(map) = ssim_maps.first() { println!("\nSSIM Map Statistics:"); println!(" Size: {}x{}", map.map.width(), map.map.height()); println!(" Average SSIM: {:.4}", map.ssim); // Find regions with lowest similarity let min_ssim = map.map.pixels().fold(1.0_f32, f32::min); let max_diff = 1.0 - min_ssim; println!(" Worst local difference: {:.4}", max_diff); } Ok(()) } ``` -------------------------------- ### Cargo.toml Dependency: Full Crate Source: https://context7.com/kornelski/dssim/llms.txt Example `Cargo.toml` configuration for using the full `dssim` crate, which includes image loading capabilities. ```toml # Full dssim crate with image loading [dependencies] dssim = "3.4" ``` -------------------------------- ### Cargo.toml Dependency: Standard Usage Source: https://context7.com/kornelski/dssim/llms.txt Example `Cargo.toml` configuration for standard DSSIM usage, including threading support. ```toml # Cargo.toml dependency examples # Standard usage with threading [dependencies] dssim-core = "3.4" ``` -------------------------------- ### Create DssimImage from RGBA u8 pixels Source: https://context7.com/kornelski/dssim/llms.txt Preprocess raw RGBA u8 pixel data into a `DssimImage` format. This example converts sRGB non-premultiplied alpha-last RGBA u8 data into the linear light premultiplied alpha format required by DSSIM. ```rust use dssim_core::{Dssim, ToRGBAPLU, RGBLU}; use imgref::{Img, ImgVec}; use rgb::RGBA; let dssim = Dssim::new(); // From RGBA u8 pixels (most common format) let rgba_pixels: Vec> = vec![ RGBA { r: 255, g: 0, b: 0, a: 255 }, RGBA { r: 0, g: 255, b: 0, a: 255 }, RGBA { r: 0, g: 0, b: 255, a: 255 }, RGBA { r: 255, g: 255, b: 0, a: 255 }, ]; // Convert to linear light premultiplied alpha format let linear_pixels = rgba_pixels.to_rgbaplu(); let img = Img::new(linear_pixels, 2, 2); // 2x2 image let dssim_image = dssim.create_image(&img).expect("Image too small"); // From RGB linear float pixels (already in linear light space) let rgb_linear: Vec = vec![ rgb::RGB::new(0.5, 0.5, 0.5), rgb::RGB::new(1.0, 0.0, 0.0), ]; let img: ImgVec = Img::new(rgb_linear, 2, 1); let dssim_image = dssim.create_image(&img.as_ref()).expect("Image too small"); // From grayscale float pixels (linear light, 0.0-1.0) let gray_pixels: Vec = vec![0.0, 0.25, 0.5, 0.75, 1.0, 0.5, 0.25, 0.0, 0.1]; let img = Img::new(gray_pixels, 3, 3); let dssim_image = dssim.create_image(&img).expect("Image too small"); ``` -------------------------------- ### Configure DSSIM-Core for WASM without Threads Source: https://github.com/kornelski/dssim/blob/main/README.md Example Cargo.toml configuration to disable the default 'threads' feature for dssim-core, ensuring compatibility with single-threaded WASM runtimes. ```toml dssim-core = { version = "3.2", default-features = false } ``` -------------------------------- ### Build DSSIM from Source Source: https://github.com/kornelski/dssim/blob/main/README.md Instructions for building the DSSIM release binary from source code using Rust. Requires Rust 1.63 or later. ```bash rustup update cargo build --release ``` -------------------------------- ### Show DSSIM CLI help and version Source: https://context7.com/kornelski/dssim/llms.txt Display help information and version details for the `dssim` command-line tool using the `-h` flag. ```bash dssim -h ``` -------------------------------- ### Build DSSIM-core Library for C Usage Source: https://github.com/kornelski/dssim/blob/main/dssim-core/README.md Builds the dssim-core library as a static archive (`.a`) for use in C projects. Ensure you are in the `dssim-core` directory. The header file `dssim.h` is also provided in the repository. ```bash cd dssim-core rustup update cargo build --release ``` -------------------------------- ### Create DSSIM comparison context with default settings Source: https://context7.com/kornelski/dssim/llms.txt Instantiate a new DSSIM comparison context using default settings, which includes 5 weighted scales for multi-resolution analysis. This can be done using `Dssim::new()` or the module-level function `dssim_core::new()`. ```rust use dssim_core::Dssim; // Create a new comparison context with default weights let dssim = Dssim::new(); // Alternative using the module-level function let dssim = dssim_core::new(); ``` -------------------------------- ### Build DSSIM with WebP Support Source: https://context7.com/kornelski/dssim/llms.txt Builds the DSSIM library with optional WebP image format support enabled. ```bash # Build with optional WebP support cargo build --release --features webp ``` -------------------------------- ### Build DSSIM with AVIF Support Source: https://context7.com/kornelski/dssim/llms.txt Builds the DSSIM library with optional AVIF image format support enabled. ```bash # Build with AVIF support cargo build --release --features avif ``` -------------------------------- ### Dssim::new() Source: https://context7.com/kornelski/dssim/llms.txt Creates a new DSSIM comparison context with default settings, utilizing 5 weighted scales for multi-resolution analysis. ```APIDOC ## Dssim::new() Creates a new DSSIM comparison context with default settings. The context uses 5 weighted scales (inspired by IW-SSIM) to measure features at different resolutions. ### Usage ```rust use dssim_core::Dssim; // Create a new comparison context with default weights let dssim = Dssim::new(); // Alternative using the module-level function let dssim = dssim_core::new(); ``` ``` -------------------------------- ### Build DSSIM Core Library for C/FFI Source: https://context7.com/kornelski/dssim/llms.txt Builds the core DSSIM library as a static library suitable for C Foreign Function Interface (FFI) usage. The static library will be located in `dssim-core/target/release/libdssim_core.a`. ```bash # Build the core library for C/FFI usage cd dssim-core cargo build --release # Static library at: target/release/libdssim_core.a ``` -------------------------------- ### Build DSSIM Command-Line Tool Source: https://context7.com/kornelski/dssim/llms.txt Builds the DSSIM command-line tool in release mode. The executable will be located at `./target/release/dssim`. ```bash # Build the command-line tool cargo build --release # Binary at: ./target/release/dssim ``` -------------------------------- ### Basic DSSIM Command-Line Usage Source: https://github.com/kornelski/dssim/blob/main/README.md Compares two PNG or JPEG images and outputs a dissimilarity score. Lower values indicate greater similarity. ```bash dssim file-original.png file-modified.png ``` -------------------------------- ### Command Line Interface Source: https://context7.com/kornelski/dssim/llms.txt The `dssim` command-line tool compares images and outputs dissimilarity scores. It supports various image formats and can generate visual difference maps. ```APIDOC ## Command Line Interface The `dssim` command compares a reference image against one or more modified images, outputting dissimilarity scores. It supports PNG, JPEG, and optionally WebP and AVIF formats. ### Usage Examples ```bash # Compare two images - outputs dissimilarity score (0 = identical, higher = more different) dssim original.png modified.png # Output: 0.00234567 modified.png # Compare multiple images against a reference dssim reference.png modified1.png modified2.png modified3.png # Output: # 0.00234567 modified1.png # 0.01523456 modified2.png # 0.00089123 modified3.png # Generate visual difference map showing where images differ dssim -o difference.png original.png modified.png # Creates difference.png-0.png, difference.png-1.png, etc. (one per scale) # Show help and version information dssim -h ``` ``` -------------------------------- ### Create DssimImage directly from RGB u8 pixels Source: https://context7.com/kornelski/dssim/llms.txt Use `create_image_rgb` for a convenient way to create a `DssimImage` directly from slices of RGB u8 pixels without manual color space conversion. Assumes sRGB format. ```rust use dssim_core::Dssim; use rgb::{RGB, RGBA}; let dssim = Dssim::new(); // Create from RGB u8 pixels (sRGB, no alpha) let rgb_data: Vec> = vec![ RGB { r: 255, g: 0, b: 0 }, RGB { r: 0, g: 255, b: 0 }, RGB { r: 0, g: 0, b: 255 }, RGB { r: 255, g: 255, b: 255 }, ]; let image = dssim.create_image_rgb(&rgb_data, 2, 2) .expect("Invalid dimensions"); ``` -------------------------------- ### Compare two images using DSSIM CLI Source: https://context7.com/kornelski/dssim/llms.txt Use the `dssim` command to compare two images. A score of 0 indicates identical images, while higher values signify greater differences. ```bash dssim original.png modified.png ``` -------------------------------- ### Dssim::create_image_rgba() / Dssim::create_image_rgb() Source: https://context7.com/kornelski/dssim/llms.txt Convenience methods for creating `DssimImage` directly from slices of RGB or RGBA u8 pixels, simplifying the conversion process. ```APIDOC ## Dssim::create_image_rgba() / Dssim::create_image_rgb() Convenience methods that directly accept slices of RGB or RGBA u8 pixels without requiring manual conversion to linear light format. ### Usage ```rust use dssim_core::Dssim; use rgb::{RGB, RGBA}; let dssim = Dssim::new(); // Create from RGBA u8 pixels (sRGB, non-premultiplied, alpha last) let rgba_data: Vec> = vec![ RGBA { r: 255, g: 128, b: 64, a: 255 }, RGBA { r: 0, g: 255, b: 128, a: 200 }, RGBA { r: 128, g: 0, b: 255, a: 128 }, RGBA { r: 64, g: 64, b: 64, a: 255 }, ]; let image = dssim.create_image_rgba(&rgba_data, 2, 2) .expect("Invalid dimensions"); // Create from RGB u8 pixels (sRGB, no alpha) let rgb_data: Vec> = vec![ RGB { r: 255, g: 0, b: 0 }, RGB { r: 0, g: 255, b: 0 }, RGB { r: 0, g: 0, b: 255 }, RGB { r: 255, g: 255, b: 255 }, ]; let image = dssim.create_image_rgb(&rgb_data, 2, 2) .expect("Invalid dimensions"); ``` ``` -------------------------------- ### Generate Difference Visualization with DSSIM Source: https://github.com/kornelski/dssim/blob/main/README.md Compares two images and saves a visualization of the differences to a specified output file. ```bash dssim -o difference.png file.png file-modified.png ``` -------------------------------- ### Create DssimImage directly from RGBA u8 pixels Source: https://context7.com/kornelski/dssim/llms.txt Use `create_image_rgba` for a convenient way to create a `DssimImage` directly from slices of RGBA u8 pixels without manual color space conversion. Assumes sRGB, non-premultiplied, alpha-last format. ```rust use dssim_core::Dssim; use rgb::{RGB, RGBA}; let dssim = Dssim::new(); // Create from RGBA u8 pixels (sRGB, non-premultiplied, alpha last) let rgba_data: Vec> = vec![ RGBA { r: 255, g: 128, b: 64, a: 255 }, RGBA { r: 0, g: 255, b: 128, a: 200 }, RGBA { r: 128, g: 0, b: 255, a: 128 }, RGBA { r: 64, g: 64, b: 64, a: 255 }, ]; let image = dssim.create_image_rgba(&rgba_data, 2, 2) .expect("Invalid dimensions"); ``` -------------------------------- ### Generate visual difference map with DSSIM CLI Source: https://context7.com/kornelski/dssim/llms.txt Use the `-o` flag to generate a visual difference map. This creates image files (e.g., `difference.png-0.png`) showing differences at various scales. ```bash dssim -o difference.png original.png modified.png ``` -------------------------------- ### load_image() Source: https://context7.com/kornelski/dssim/llms.txt High-level function to load PNG or JPEG images from disk with automatic color profile handling and conversion to sRGB. ```APIDOC ## load_image() (dssim crate) ### Description High-level function to load PNG or JPEG images from disk with automatic color profile handling and conversion to sRGB. ### Method `load_image` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use dssim::{Dssim, load_image}; use std::path::Path; let dssim = Dssim::new(); // Load images from files (handles PNG, JPEG, and optionally WebP/AVIF) let original = load_image(&dssim, Path::new("original.png")) .expect("Failed to load original image"); let modified = load_image(&dssim, Path::new("modified.jpg")) .expect("Failed to load modified image"); // Images are automatically converted to sRGB with color profile support let (score, _) = dssim.compare(&original, &modified); println!("Difference: {:.6}", score); // Works with various image formats and color depths let gray_img = load_image(&dssim, "grayscale.png").unwrap(); let rgba_img = load_image(&dssim, "transparent.png").unwrap(); let profiled_img = load_image(&dssim, "adobergb-image.jpg").unwrap(); // Auto-converted ``` ### Response #### Success Response (200) - **Image** (Img) - The loaded image, converted to sRGB. #### Response Example ```json { "width": 1920, "height": 1080, "pixels": [ ... ] // Pixel data } ``` ``` -------------------------------- ### Load Images with Dssim Source: https://context7.com/kornelski/dssim/llms.txt Loads PNG or JPEG images from disk using `load_image`. This function handles automatic color profile conversion to sRGB and supports various image formats and color depths. It's a high-level utility for preparing images for comparison. ```rust use dssim::{Dssim, load_image}; use std::path::Path; let dssim = Dssim::new(); // Load images from files (handles PNG, JPEG, and optionally WebP/AVIF) let original = load_image(&dssim, Path::new("original.png")) .expect("Failed to load original image"); let modified = load_image(&dssim, Path::new("modified.jpg")) .expect("Failed to load modified image"); // Images are automatically converted to sRGB with color profile support let (score, _) = dssim.compare(&original, &modified); println!("Difference: {:.6}", score); // Works with various image formats and color depths let gray_img = load_image(&dssim, "grayscale.png").unwrap(); let rgba_img = load_image(&dssim, "transparent.png").unwrap(); let profiled_img = load_image(&dssim, "adobergb-image.jpg").unwrap(); // Auto-converted ``` -------------------------------- ### Dssim::create_image() Source: https://context7.com/kornelski/dssim/llms.txt Converts raw pixel data into a preprocessed `DssimImage` optimized for comparison. Supports various pixel formats including RGBA premultiplied linear, RGB linear, and grayscale. ```APIDOC ## Dssim::create_image() Converts raw pixel data into a preprocessed `DssimImage` optimized for comparison. Accepts various pixel formats via the `imgref` crate including RGBA premultiplied linear (`RGBAPLU`), RGB linear (`RGBLU`), and grayscale (`f32`). ### Usage ```rust use dssim_core::{Dssim, ToRGBAPLU, RGBLU}; use imgref::{Img, ImgVec}; use rgb::RGBA; let dssim = Dssim::new(); // From RGBA u8 pixels (most common format) let rgba_pixels: Vec> = vec![ RGBA { r: 255, g: 0, b: 0, a: 255 }, RGBA { r: 0, g: 255, b: 0, a: 255 }, RGBA { r: 0, g: 0, b: 255, a: 255 }, RGBA { r: 255, g: 255, b: 0, a: 255 }, ]; // Convert to linear light premultiplied alpha format let linear_pixels = rgba_pixels.to_rgbaplu(); let img = Img::new(linear_pixels, 2, 2); // 2x2 image let dssim_image = dssim.create_image(&img).expect("Image too small"); // From RGB linear float pixels (already in linear light space) let rgb_linear: Vec = vec![ rgb::RGB::new(0.5, 0.5, 0.5), rgb::RGB::new(1.0, 0.0, 0.0), ]; let img: ImgVec = Img::new(rgb_linear, 2, 1); let dssim_image = dssim.create_image(&img.as_ref()).expect("Image too small"); // From grayscale float pixels (linear light, 0.0-1.0) let gray_pixels: Vec = vec![0.0, 0.25, 0.5, 0.75, 1.0, 0.5, 0.25, 0.0, 0.1]; let img = Img::new(gray_pixels, 3, 3); let dssim_image = dssim.create_image(&img).expect("Image too small"); ``` ``` -------------------------------- ### Configure Custom Scales for Dssim Source: https://context7.com/kornelski/dssim/llms.txt Configures custom scale weights for multi-resolution comparison. This allows for faster but potentially less accurate comparisons by adjusting the number and weights of scales used. Default uses 5 scales optimized for perceptual accuracy. ```rust use dssim_core::Dssim; let mut dssim = Dssim::new(); // Use custom weights for 3-scale comparison (faster but less accurate) dssim.set_scales(&[0.25, 0.50, 0.25]); // Use more scales for higher accuracy on large images dssim.set_scales(&[0.02, 0.10, 0.20, 0.30, 0.25, 0.13]); // Default weights (for reference): // [0.028, 0.197, 0.322, 0.298, 0.155] ``` -------------------------------- ### Build DSSIM for WASM Source: https://context7.com/kornelski/dssim/llms.txt Builds DSSIM for WebAssembly (WASM), disabling default features for compatibility with single-threaded runtimes. ```bash # Build for WASM (disable threads for single-threaded runtime compatibility) # In Cargo.toml: # dssim-core = { version = "3.4", default-features = false } ``` -------------------------------- ### Convert RGBA to Linear Premultiplied Alpha (RGBAPLU) Source: https://context7.com/kornelski/dssim/llms.txt Converts a slice of RGBA pixels to DSSIM's internal linear-light premultiplied alpha format. Alpha is preserved, and RGB values are converted to linear light and premultiplied. ```rust use dssim_core::ToRGBAPLU; use rgb::{RGB, RGBA}; // Convert RGBA slice to RGBAPLU (premultiplied alpha, linear light) let rgba_pixels: Vec> = vec![ RGBA { r: 255, g: 0, b: 0, a: 255 }, // Opaque red RGBA { r: 0, g: 255, b: 0, a: 128 }, // Semi-transparent green RGBA { r: 0, g: 0, b: 255, a: 0 }, // Fully transparent blue ]; let linear_premul: Vec<_> = rgba_pixels.to_rgbaplu(); // Alpha is preserved, RGB values are converted to linear light and premultiplied // Convert to RGBLU (linear light, discards alpha) let linear_rgb: Vec<_> = rgba_pixels.to_rgblu(); // Also works with RGB (no alpha to begin with) let rgb_pixels: Vec> = vec![ RGB { r: 255, g: 128, b: 64 }, RGB { r: 0, g: 255, b: 128 }, ]; let linear: Vec<_> = rgb_pixels.to_rgbaplu(); // Alpha set to 1.0 // Works with 16-bit pixels too let rgba16: Vec> = vec![ RGBA { r: 65535, g: 32768, b: 0, a: 65535 }, ]; let linear_16bit: Vec<_> = rgba16.to_rgbaplu(); ``` -------------------------------- ### Evaluate CSV Files with Python Source: https://github.com/kornelski/dssim/blob/main/clic-2021/README.md Navigate to the clic_2021_perceptual_valid directory and run the eval_csv.py script to compare the oracle CSV with the generated CSV. Ensure you are in the correct directory before execution. ```bash cd clic_2021_perceptual_valid python3 eval_csv.py --oracle_csv=oracle.csv --eval_csv=../dssim3.csv ``` -------------------------------- ### Compare Multiple Images with DSSIM Source: https://github.com/kornelski/dssim/blob/main/README.md Compares multiple modified images against a single original image, outputting a dissimilarity score for each comparison. ```bash dssim file.png modified1.png modified2.png modified3.png ``` -------------------------------- ### Run clic-2021 Binary Source: https://github.com/kornelski/dssim/blob/main/clic-2021/README.md Execute the clic-2021 binary with the path to the CSV file as the first argument. This command generates a dssim3.csv file in the current directory. ```rust cargo run --release clic_2021_perceptual_valid/validation.csv ``` -------------------------------- ### Dssim::compare() Source: https://context7.com/kornelski/dssim/llms.txt Compares two preprocessed images and returns a dissimilarity score. Optionally returns per-pixel SSIM maps. ```APIDOC ## Dssim::compare() ### Description Compares two preprocessed images and returns a dissimilarity score. The result is a `Val` type (wrapper for `f64`) where 0 means identical and larger values indicate more difference. Optionally returns per-pixel SSIM maps if enabled. ### Method `compare` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use dssim_core::{Dssim, ToRGBAPLU}; use imgref::Img; use rgb::RGBA; let dssim = Dssim::new(); // Create two test images let original_pixels: Vec> = vec![RGBA { r: 100, g: 100, b: 100, a: 255 }; 64 * 64]; let modified_pixels: Vec> = vec![RGBA { r: 105, g: 100, b: 100, a: 255 }; 64 * 64]; let original = dssim.create_image(&Img::new(original_pixels.to_rgbaplu(), 64, 64)).unwrap(); let modified = dssim.create_image(&Img::new(modified_pixels.to_rgbaplu(), 64, 64)).unwrap(); // Compare images - returns (dissimilarity_score, ssim_maps) let (score, _maps) = dssim.compare(&original, &modified); println!("DSSIM score: {:.6}", score); // e.g., "DSSIM score: 0.000234" // Score interpretation: // 0.0 = identical images // < 0.001 = very similar, differences barely perceptible // 0.001-0.01 = noticeable differences // > 0.01 = significant visual differences // Check if images are "close enough" if score < 0.001 { println!("Images are nearly identical"); } ``` ### Response #### Success Response (200) - **score** (Val) - The dissimilarity score between the two images. - **maps** (Vec) - Optional per-pixel SSIM maps if enabled. #### Response Example ```json { "score": 0.000234, "maps": [ { "scale": 0, "ssim": 0.999766, "map": { "width": 64, "height": 64, "pixels": [ ... ] // Array of f32 SSIM values per pixel } } // ... other scales ] } ``` ``` -------------------------------- ### Compare Images with Dssim Source: https://context7.com/kornelski/dssim/llms.txt Compares two preprocessed images using Dssim and returns a dissimilarity score. The score ranges from 0 (identical) upwards. Optionally, per-pixel SSIM maps can be returned. Use this for direct image quality assessment. ```rust use dssim_core::{Dssim, ToRGBAPLU}; use imgref::Img; use rgb::RGBA; let dssim = Dssim::new(); // Create two test images let original_pixels: Vec> = vec![ RGBA { r: 100, g: 100, b: 100, a: 255 }; 64 * 64 ]; let modified_pixels: Vec> = vec![ RGBA { r: 105, g: 100, b: 100, a: 255 }; 64 * 64 ]; let original = dssim.create_image(&Img::new(original_pixels.to_rgbaplu(), 64, 64)).unwrap(); let modified = dssim.create_image(&Img::new(modified_pixels.to_rgbaplu(), 64, 64)).unwrap(); // Compare images - returns (dissimilarity_score, ssim_maps) let (score, _maps) = dssim.compare(&original, &modified); println!("DSSIM score: {:.6}", score); // e.g., "DSSIM score: 0.000234" // Score interpretation: // 0.0 = identical images // < 0.001 = very similar, differences barely perceptible // 0.001-0.01 = noticeable differences // > 0.01 = significant visual differences // Check if images are "close enough" if score < 0.001 { println!("Images are nearly identical"); } ``` -------------------------------- ### Dssim::set_scales() Source: https://context7.com/kornelski/dssim/llms.txt Configures custom scale weights for multi-resolution comparison. The default uses 5 scales with weights optimized for perceptual accuracy. ```APIDOC ## Dssim::set_scales() ### Description Configures custom scale weights for multi-resolution comparison. Default uses 5 scales with weights optimized for perceptual accuracy. ### Method `set_scales` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use dssim_core::Dssim; let mut dssim = Dssim::new(); // Use custom weights for 3-scale comparison (faster but less accurate) dssim.set_scales(&[0.25, 0.50, 0.25]); // Use more scales for higher accuracy on large images dssim.set_scales(&[0.02, 0.10, 0.20, 0.30, 0.25, 0.13]); // Default weights (for reference): // [0.028, 0.197, 0.322, 0.298, 0.155] ``` ### Response #### Success Response (200) This method does not return a value, it configures the `Dssim` instance. #### Response Example None ``` -------------------------------- ### Enable SSIM Map Saving in Dssim Source: https://context7.com/kornelski/dssim/llms.txt Enables saving per-pixel SSIM maps for visualization, which is useful for identifying the specific locations of differences within an image. The number passed to `set_save_ssim_maps` determines how many scales' maps are generated. ```rust use dssim_core::{Dssim, ToRGBAPLU}; use imgref::Img; use rgb::RGBA; let mut dssim = Dssim::new(); // Save SSIM maps for the first 4 scales dssim.set_save_ssim_maps(4); // Create and compare images let pixels1: Vec> = vec![RGBA { r: 128, g: 128, b: 128, a: 255 }; 128 * 128]; let pixels2: Vec> = vec![RGBA { r: 130, g: 128, b: 128, a: 255 }; 128 * 128]; let img1 = dssim.create_image(&Img::new(pixels1.to_rgbaplu(), 128, 128)).unwrap(); let img2 = dssim.create_image(&Img::new(pixels2.to_rgbaplu(), 128, 128)).unwrap(); let (score, ssim_maps) = dssim.compare(&img1, &img2); // Process SSIM maps (one per scale) for (scale_idx, map) in ssim_maps.iter().enumerate() { println!("Scale {}: {}x{}, avg SSIM: {:.4}", scale_idx, map.map.width(), map.map.height(), map.ssim); // Access per-pixel SSIM values (0.0-1.0, higher = more similar) for pixel_ssim in map.map.pixels() { // pixel_ssim is f32 SSIM value for that location let difference = 1.0 - pixel_ssim; // Use difference to create visualization... } } ``` -------------------------------- ### Dssim::set_save_ssim_maps() Source: https://context7.com/kornelski/dssim/llms.txt Enables saving per-pixel SSIM maps for visualization, which is useful for identifying where in an image differences occur. ```APIDOC ## Dssim::set_save_ssim_maps() ### Description Enables saving per-pixel SSIM maps for visualization. Useful for identifying where in an image differences occur. ### Method `set_save_ssim_maps` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use dssim_core::{Dssim, ToRGBAPLU}; use imgref::Img; use rgb::RGBA; let mut dssim = Dssim::new(); // Save SSIM maps for the first 4 scales dssim.set_save_ssim_maps(4); // Create and compare images let pixels1: Vec> = vec![RGBA { r: 128, g: 128, b: 128, a: 255 }; 128 * 128]; let pixels2: Vec> = vec![RGBA { r: 130, g: 128, b: 128, a: 255 }; 128 * 128]; let img1 = dssim.create_image(&Img::new(pixels1.to_rgbaplu(), 128, 128)).unwrap(); let img2 = dssim.create_image(&Img::new(pixels2.to_rgbaplu(), 128, 128)).unwrap(); let (score, ssim_maps) = dssim.compare(&img1, &img2); // Process SSIM maps (one per scale) for (scale_idx, map) in ssim_maps.iter().enumerate() { println!("Scale {}: {}x{}, avg SSIM: {:.4}", scale_idx, map.map.width(), map.map.height(), map.ssim); // Access per-pixel SSIM values (0.0-1.0, higher = more similar) for pixel_ssim in map.map.pixels() { // pixel_ssim is f32 SSIM value for that location let difference = 1.0 - pixel_ssim; // Use difference to create visualization... } } ``` ### Response #### Success Response (200) This method does not return a value, it configures the `Dssim` instance to save SSIM maps. #### Response Example None ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.