Skip to main content

Crate imgfprint

Crate imgfprint 

Source
Expand description

High-performance, deterministic image fingerprinting library.

Provides perceptual hashing with crop resistance for image deduplication and similarity detection in production systems.

Supports multiple algorithms (PHash, DHash) with automatic parallel computation for improved accuracy.

§Quick Start

Compute all hashes (recommended for best accuracy):

use imgfprint::ImageFingerprinter;
let fp1 = ImageFingerprinter::fingerprint(&std::fs::read("img1.jpg")?)?;
let fp2 = ImageFingerprinter::fingerprint(&std::fs::read("img2.jpg")?)?;

let sim = fp1.compare(&fp2);
println!("Similarity: {:.2}", sim.score);

Compute specific algorithm only:

use imgfprint::{ImageFingerprinter, HashAlgorithm};

let fp = ImageFingerprinter::fingerprint_with(
    &std::fs::read("img1.jpg")?,
    HashAlgorithm::DHash
)?;

§High-Throughput Usage

For processing many images, use FingerprinterContext to enable buffer reuse and avoid repeated allocations:

use imgfprint::FingerprinterContext;

let mut ctx = FingerprinterContext::new();

// Process multiple images efficiently
for path in &["img1.jpg", "img2.jpg", "img3.jpg"] {
    let fp = ctx.fingerprint(&std::fs::read(path)?)?;
    // Use fingerprint...
}

§Performance Features

  • SIMD-accelerated resize: Uses AVX2/NEON instructions for 3-4x faster resizing
  • Cached DCT plans: Reuses DCT computation plans across all calls
  • Buffer reuse: Context API minimizes allocations in high-throughput scenarios
  • Parallel processing: Batch operations use rayon for multi-core speedup

Structs§

Embedding
A semantic embedding vector representing image content.
FingerprinterContext
Context for high-performance fingerprinting with buffer reuse.
ImageFingerprint
A perceptual fingerprint containing multiple hash layers for robust comparison.
ImageFingerprinter
Static methods for computing and comparing image fingerprints.
MultiHashFingerprint
A multi-algorithm fingerprint containing hashes from multiple perceptual algorithms.
Similarity
Similarity score between two image fingerprints.

Enums§

HashAlgorithm
Available perceptual hash algorithms.
ImgFprintError
Errors that can occur during image fingerprinting.

Traits§

EmbeddingProvider
Trait for embedding providers.

Functions§

semantic_similarity
Computes cosine similarity between two embeddings.