Skip to main content

DHasher

Struct DHasher 

Source
pub struct DHasher { /* private fields */ }
Expand description

Difference hash (dHash) for fast duplicate detection.

dHash computes a gradient-based hash by comparing adjacent pixels. It’s very fast and works well for detecting near-duplicate frames.

§Algorithm

  1. Resize image to (hash_width + 1, hash_height)
  2. Convert to grayscale
  3. Compare each pixel to its right neighbor
  4. Set bit to 1 if left > right, else 0

§Example

use figif_core::hashers::DHasher;
use figif_core::traits::FrameHasher;

let hasher = DHasher::new();
let hash = hasher.hash_frame(&image);

Implementations§

Source§

impl DHasher

Source

pub fn new() -> Self

Create a new dHash hasher with default 8x8 hash size.

Source

pub fn with_size(width: u32, height: u32) -> Self

Create a dHash hasher with custom hash dimensions.

Larger sizes provide more precision but slower comparison. Common sizes: 8x8 (64-bit), 16x16 (256-bit).

Source

pub fn hash_width(&self) -> u32

Get the hash width.

Source

pub fn hash_height(&self) -> u32

Get the hash height.

Source

pub fn hash_bits(&self) -> u32

Get the total hash bits.

Trait Implementations§

Source§

impl Clone for DHasher

Source§

fn clone(&self) -> DHasher

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 DHasher

Source§

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

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

impl Default for DHasher

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl FrameHasher for DHasher

Source§

type Hash = ImageHash

The hash type produced by this hasher. Read more
Source§

fn hash_frame(&self, image: &RgbaImage) -> Self::Hash

Compute the perceptual hash for a single frame. Read more
Source§

fn distance(&self, a: &Self::Hash, b: &Self::Hash) -> u32

Compute the distance between two hashes. Read more
Source§

fn name(&self) -> &'static str

Get the name of this hasher for logging/debugging.
Source§

fn suggested_threshold(&self) -> u32

Suggested threshold for considering frames as duplicates. Read more

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> FrameHasherExt for T
where T: FrameHasher,

Source§

fn hash_frames(&self, images: &[RgbaImage]) -> Vec<Self::Hash>

Hash multiple frames, returning a vector of hashes.
Source§

fn are_duplicates(&self, a: &RgbaImage, b: &RgbaImage) -> bool

Check if two frames are duplicates using the suggested threshold.
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> ParallelFrameHasher for T
where T: FrameHasher,

Source§

fn hash_frames_parallel(&self, images: &[RgbaImage]) -> Vec<Self::Hash>
where Self::Hash: Send,

Hash multiple frames in parallel.
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.