pub struct ImageFingerprint { /* private fields */ }Expand description
A perceptual fingerprint containing multiple hash layers for robust comparison.
Fingerprints are deterministic and comparable across platforms. The structure includes exact hashing for identical detection and perceptual hashing for similarity detection with resistance to resizing, compression, and cropping.
Implementations§
Source§impl ImageFingerprint
impl ImageFingerprint
Sourcepub fn exact_hash(&self) -> &[u8; 32]
pub fn exact_hash(&self) -> &[u8; 32]
Returns the BLAKE3 hash of the original image bytes.
Two images with identical byte content will have matching exact hashes. Use this for exact deduplication before perceptual comparison.
Sourcepub fn global_hash(&self) -> u64
pub fn global_hash(&self) -> u64
Returns the global perceptual hash from the center 32x32 region.
This hash captures the overall structure of the image and is robust
to minor changes in compression and color adjustments. The algorithm
used (PHash or DHash) depends on which was specified when creating the fingerprint.
Sourcepub fn block_hashes(&self) -> &[u64; 16]
pub fn block_hashes(&self) -> &[u64; 16]
Returns the 16 block-level perceptual hashes from a 4x4 grid.
Block hashes enable crop-resistant comparison by matching partial regions between images. Each hash covers a 64x64 pixel region.
Sourcepub fn distance(&self, other: &ImageFingerprint) -> u32
pub fn distance(&self, other: &ImageFingerprint) -> u32
Computes the Hamming distance between this and another fingerprint’s global hash.
Returns a value from 0 (identical) to 64 (completely different).
Sourcepub fn is_similar(&self, other: &ImageFingerprint, threshold: f32) -> bool
pub fn is_similar(&self, other: &ImageFingerprint, threshold: f32) -> bool
Checks if this fingerprint is similar to another within a threshold.
§Arguments
other- The fingerprint to compare againstthreshold- Similarity threshold from 0.0 to 1.0 (default: 0.8)
§Panics
Panics in debug mode if threshold is not in [0.0, 1.0]. In release mode, out-of-range or NaN thresholds return false (never similar).
§Example
// Use ImageFingerprinter::fingerprint() to create fingerprints first
use imgfprint::ImageFingerprinter;
let fp1 = ImageFingerprinter::fingerprint(&std::fs::read("image1.jpg")?).unwrap();
let fp2 = ImageFingerprinter::fingerprint(&std::fs::read("image2.jpg")?).unwrap();
if fp1.is_similar(&fp2, 0.8) {
println!("Images are similar!");
}Trait Implementations§
Source§impl Clone for ImageFingerprint
impl Clone for ImageFingerprint
Source§fn clone(&self) -> ImageFingerprint
fn clone(&self) -> ImageFingerprint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ImageFingerprint
impl Debug for ImageFingerprint
Source§impl<'de> Deserialize<'de> for ImageFingerprint
impl<'de> Deserialize<'de> for ImageFingerprint
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ImageFingerprint
impl PartialEq for ImageFingerprint
Source§impl Serialize for ImageFingerprint
impl Serialize for ImageFingerprint
impl Eq for ImageFingerprint
impl StructuralPartialEq for ImageFingerprint
Auto Trait Implementations§
impl Freeze for ImageFingerprint
impl RefUnwindSafe for ImageFingerprint
impl Send for ImageFingerprint
impl Sync for ImageFingerprint
impl Unpin for ImageFingerprint
impl UnsafeUnpin for ImageFingerprint
impl UnwindSafe for ImageFingerprint
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