#image #hash #perceptual #difference

bin+lib image_hasher

A simple library that provides perceptual hashing and difference calculation for images

3 stable releases

Uses new Rust 2021

1.1.2 Nov 26, 2022
1.1.1 Nov 20, 2022
1.1.0 Oct 20, 2022
1.0.0 Apr 2, 2022

#88 in Images

Download history 157/week @ 2022-08-19 281/week @ 2022-08-26 175/week @ 2022-09-02 252/week @ 2022-09-09 252/week @ 2022-09-16 199/week @ 2022-09-23 193/week @ 2022-09-30 220/week @ 2022-10-07 1305/week @ 2022-10-14 1695/week @ 2022-10-21 1164/week @ 2022-10-28 1410/week @ 2022-11-04 854/week @ 2022-11-11 958/week @ 2022-11-18 963/week @ 2022-11-25 553/week @ 2022-12-02

3,499 downloads per month
Used in 5 crates

MIT/Apache

53KB
962 lines

Image Hasher

A library for getting perceptual hash values of images.

Thanks to Dr. Neal Krawetz for the outlines of the Mean (aHash), Gradient (dHash), and DCT (pHash) perceptual hash algorithms:
http://www.hackerfactor.com/blog/?/archives/432-Looks-Like-It.html (Accessed August 2014)

Also provides an implementation of the Blockhash.io algorithm.

This crate can operate directly on buffers from the PistonDevelopers/image crate.

This is fork of img_hash library, but with updated dependencies without any license changes.

Usage

Documentation

Add image_hasher to your Cargo.toml:

image_hasher = "1.1.0"

Example program:

 use imgage_hasher::{HasherConfig, HashAlg};

 fn main() {
     let image1 = image::open("image1.png").unwrap();
     let image2 = image::open("image2.png").unwrap();
     
     let hasher = HasherConfig::new().to_hasher();

     let hash1 = hasher.hash_image(&image1);
     let hash2 = hasher.hash_image(&image2);
     
     println!("Image1 hash: {}", hash1.to_base64());
     println!("Image2 hash: {}", hash2.to_base64());
     
     println!("Hamming Distance: {}", hash1.dist(&hash2));
 }

Benchmarking

In order to build and test on Rust stable, the benchmarks have to be placed behind a feature gate. If you have Rust nightly installed and want to run benchmarks, use the following command:

cargo +nightly bench

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~5MB
~104K SLoC