#image #hash #perceptual #difference

bin+lib image_hasher

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

4 stable releases

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

#89 in Algorithms

Download history 1181/week @ 2023-08-11 1402/week @ 2023-08-18 1472/week @ 2023-08-25 1907/week @ 2023-09-01 1831/week @ 2023-09-08 1940/week @ 2023-09-15 2014/week @ 2023-09-22 1831/week @ 2023-09-29 2094/week @ 2023-10-06 2620/week @ 2023-10-13 2395/week @ 2023-10-20 2046/week @ 2023-10-27 2230/week @ 2023-11-03 2099/week @ 2023-11-10 2449/week @ 2023-11-17 1995/week @ 2023-11-24

9,140 downloads per month
Used in 6 crates

MIT/Apache

54KB
966 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 image_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

~5.5MB
~108K SLoC