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
- Resize image to (hash_width + 1, hash_height)
- Convert to grayscale
- Compare each pixel to its right neighbor
- 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
impl DHasher
Sourcepub fn with_size(width: u32, height: u32) -> Self
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).
Sourcepub fn hash_width(&self) -> u32
pub fn hash_width(&self) -> u32
Get the hash width.
Sourcepub fn hash_height(&self) -> u32
pub fn hash_height(&self) -> u32
Get the hash height.
Trait Implementations§
Source§impl FrameHasher for DHasher
impl FrameHasher for DHasher
Source§fn hash_frame(&self, image: &RgbaImage) -> Self::Hash
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
fn distance(&self, a: &Self::Hash, b: &Self::Hash) -> u32
Compute the distance between two hashes. Read more
Source§fn suggested_threshold(&self) -> u32
fn suggested_threshold(&self) -> u32
Suggested threshold for considering frames as duplicates. Read more
Auto Trait Implementations§
impl Freeze for DHasher
impl RefUnwindSafe for DHasher
impl Send for DHasher
impl Sync for DHasher
impl Unpin for DHasher
impl UnsafeUnpin for DHasher
impl UnwindSafe for DHasher
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FrameHasherExt for Twhere
T: FrameHasher,
impl<T> FrameHasherExt for Twhere
T: FrameHasher,
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>
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 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>
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