#image #hash #perceptual #difference

bin+lib img_hash

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

10 stable releases (3 major)

Uses old Rust 2015

3.2.0 May 4, 2021
3.1.1 Mar 13, 2021
3.1.0 Feb 19, 2020
3.0.0 Oct 28, 2019
0.0.2 Nov 28, 2014

#16 in Images

Download history 665/week @ 2021-08-15 568/week @ 2021-08-22 435/week @ 2021-08-29 258/week @ 2021-09-05 342/week @ 2021-09-12 683/week @ 2021-09-19 816/week @ 2021-09-26 935/week @ 2021-10-03 439/week @ 2021-10-10 649/week @ 2021-10-17 1330/week @ 2021-10-24 837/week @ 2021-10-31 950/week @ 2021-11-07 1613/week @ 2021-11-14 1608/week @ 2021-11-21 1168/week @ 2021-11-28

5,385 downloads per month
Used in 10 crates (9 directly)

MIT/Apache

55KB
696 lines

img_hash Build Status Crates.io shield

Now builds on stable Rust! (But needs nightly to bench.)

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.

Usage

Documentation

Add img_hash to your Cargo.toml:

[dependencies.img_hash]
version = "3.0"

Example program:

 extern crate image;
 extern crate img_hash;
 
 use img_hash::{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 bench --features 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

~4.5MB
~94K SLoC

$`