pub struct PHasher { /* private fields */ }Expand description
Perceptual hash (pHash) using Discrete Cosine Transform.
pHash is more robust to image transformations than simpler hashes but is slower to compute. It works by analyzing the frequency components of the image.
§Algorithm
- Resize image to 32x32
- Convert to grayscale
- Apply DCT (Discrete Cosine Transform)
- Keep only low-frequency components (top-left 8x8)
- Compute median and create hash based on above/below median
§Example
ⓘ
use figif_core::hashers::PHasher;
use figif_core::traits::FrameHasher;
let hasher = PHasher::new();
let hash = hasher.hash_frame(&image);Implementations§
Source§impl PHasher
impl PHasher
Sourcepub fn with_size(width: u32, height: u32) -> Self
pub fn with_size(width: u32, height: u32) -> Self
Create a pHash hasher with custom hash dimensions.
The actual DCT is computed on a larger image (4x the hash size), then only the low-frequency components are kept.
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 PHasher
impl FrameHasher for PHasher
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 PHasher
impl RefUnwindSafe for PHasher
impl Send for PHasher
impl Sync for PHasher
impl Unpin for PHasher
impl UnsafeUnpin for PHasher
impl UnwindSafe for PHasher
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