Skip to main content

ImageFingerprint

Struct ImageFingerprint 

Source
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

Source

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.

Source

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.

Source

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.

Source

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).

Source

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 against
  • threshold - 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

Source§

fn clone(&self) -> ImageFingerprint

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ImageFingerprint

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ImageFingerprint

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ImageFingerprint

Source§

fn eq(&self, other: &ImageFingerprint) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ImageFingerprint

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for ImageFingerprint

Source§

impl StructuralPartialEq for ImageFingerprint

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,