Expand description
§imghash
imghash provides image hashing algorithms for Rust, compatible with the
Python imagehash package.
The following hash algorithms are supported:
- Average hash — compares each pixel to the mean intensity
- Median hash — compares each pixel to the median intensity
- Difference hash — compares adjacent pixels in each row
- Perceptual hash — uses DCT to capture frequency information
§Quick start
use std::path::Path;
use imghash::average_hash;
let path = Path::new("path/to/image.png");
let hash = average_hash(path).unwrap();
// Encode as a hex string
let hex = hash.encode().unwrap();
// Decode back from hex
let decoded = imghash::ImageHash::decode(&hex, 8, 8).unwrap();
// Compare two hashes
let distance = hash.distance(&decoded).unwrap();
assert_eq!(distance, 0);§Custom hashers
For more control over hash dimensions and color space, use the hasher structs directly:
use std::path::Path;
use imghash::{average::AverageHasher, ColorSpace, ImageHasher};
let hasher = AverageHasher::new(16, 16, ColorSpace::REC601).unwrap();
let hash = hasher.hash_from_path(Path::new("path/to/image.png")).unwrap();Modules§
Structs§
Enums§
Traits§
- Image
Hasher - Trait for generating image hashes
Functions§
- average_
hash - Calculate the average hash for an image at the specified path. Uses the default
width and height of 8 x 8 pixels. If you want to use something else please directly use
the
AverageHasherstruct. - difference_
hash - Calculate the difference hash for an image at the specified path. Uses the default
width and height of 8 x 8 pixels. If you want to use something else please directly use
the
DifferenceHasherstruct. - median_
hash - Calculate the median hash for an image at the specified path. Uses the default
width and height of 8 x 8 pixels. If you want to use something else please directly use
the
MedianHasherstruct. - perceptual_
hash - Calculate the perceptual hash for an image at the specified path. Uses the default
width and height of 8 x 8 pixels as well as the default factor of 4.
If you want to use something else please directly use the
PerceptualHasherstruct.