Skip to main content

PHasher

Struct PHasher 

Source
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

  1. Resize image to 32x32
  2. Convert to grayscale
  3. Apply DCT (Discrete Cosine Transform)
  4. Keep only low-frequency components (top-left 8x8)
  5. 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

Source

pub fn new() -> Self

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

Source

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.

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 PHasher

Source§

fn clone(&self) -> PHasher

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 PHasher

Source§

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

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

impl Default for PHasher

Source§

fn default() -> Self

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

impl FrameHasher for PHasher

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.