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.
§Binary layout
#[repr(C)] with no padding bytes (168 bytes total: 32 + 8 + 128). Implements
bytemuck::Pod / bytemuck::Zeroable so a &[ImageFingerprint] can be
zero-copy cast to &[u8] for mmap-based persistence:
use imgfprint::ImageFingerprint;
bytemuck::cast_slice(fps)Copy is derived because bytemuck::Pod requires it; the trade-off is
that move-by-value silently memcpys 168 bytes. Prefer borrowing
(&ImageFingerprint) in hot loops where this matters.
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 const fn format_version() -> u32
pub const fn format_version() -> u32
Returns the on-disk format version this fingerprint was computed under.
Equal to crate::FORMAT_VERSION. Persist alongside fingerprint bytes
(or in a sidecar manifest) and refuse comparison across mismatched
versions to guard against algorithm-version drift.
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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ImageFingerprint
Source§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 Display for ImageFingerprint
impl Display for ImageFingerprint
impl Eq for ImageFingerprint
Source§impl Hash for ImageFingerprint
impl Hash for ImageFingerprint
Source§impl PartialEq for ImageFingerprint
impl PartialEq for ImageFingerprint
Source§fn eq(&self, other: &ImageFingerprint) -> bool
fn eq(&self, other: &ImageFingerprint) -> bool
self and other values to be equal, and is used by ==.impl Pod for ImageFingerprint
Source§impl Serialize for ImageFingerprint
impl Serialize 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§
impl<T> AnyBitPattern for Twhere
T: Pod,
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> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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