#perceptual #hash #dhash #perceptual-hashing

fast-dhash

A fast rust implementation of the perceptual hash dhash

7 releases (stable)

new 1.1.0 Jan 20, 2025
1.0.4 Jan 20, 2025
0.1.0 Mar 29, 2023

#933 in Algorithms

Download history 2/week @ 2024-09-24 5/week @ 2024-12-10

171 downloads per month

MIT license

1MB
191 lines

Fast Dhash

A fast rust implementation of the perceptual hash dhash.

The main difference with other rust implementations, and the reason it is called fast, is that it uses multithreading and does not resize nor converts the image, effectively cycling through its bytes only once.

Usage

For forward and backward compatibility, fast dhash does NOT directly rely on the image crate, it is up to the user to provide the image bytes and dimensions.

use fast_dhash::Dhash;
use image::ImageReader;

let image = ImageReader::open(".test/radial.jpg")
    .expect("cannot read image")
    .decode()
    .expect("cannot decode image");

let hash = Dhash::new(
    image.as_bytes(),
    image.width(),
    image.height(),
    image.color().channel_count(),
);

println!("hash: {}", hash);
// hash: f0f0e8cccce8f0f0

lib.rs:

Fast Dhash

A fast rust implementation of the perceptual hash dhash.

The main difference with other rust implementations, and the reason it is called fast, is that it uses multithreading and does not resize nor converts the image, effectively cycling through its bytes only once.

Usage

For forward and backward compatibility, fast dhash does NOT directly rely on the image crate, it is up to the user to provide the image bytes and dimensions.

use fast_dhash::Dhash;
use image::ImageReader;

let image = ImageReader::open(".test/radial.jpg")
    .expect("cannot read image")
    .decode()
    .expect("cannot decode image");

let hash = Dhash::new(
    image.as_bytes(),
    image.width(),
    image.height(),
    image.color().channel_count(),
);

println!("hash: {}", hash);
// hash: f0f0e8cccce8f0f0

Dependencies