#image #perceptual #hash #difference #hash-values

bin+lib img_hash_median

A simple library that provides perceptual hashing and difference calculation for images. Includes median PHash

1 stable release

Uses old Rust 2015

4.0.0 Oct 26, 2020

#1496 in Algorithms

Download history 96/week @ 2024-03-31 60/week @ 2024-04-07 53/week @ 2024-04-14 69/week @ 2024-04-21 96/week @ 2024-04-28 67/week @ 2024-05-05 55/week @ 2024-05-12 81/week @ 2024-05-19 70/week @ 2024-05-26 66/week @ 2024-06-02 67/week @ 2024-06-09 58/week @ 2024-06-16 43/week @ 2024-06-23 44/week @ 2024-06-30 39/week @ 2024-07-07 57/week @ 2024-07-14

194 downloads per month
Used in 2 crates (via sn0int-std)

AGPL-3.0-only

56KB
718 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

~9MB
~142K SLoC