# JImageHash
**Repository Path**: nanbowang/JImageHash
## Basic Information
- **Project Name**: JImageHash
- **Description**: Perceptual image hashing library used to match similar images
- **Primary Language**: Java
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2020-02-21
- **Last Updated**: 2026-01-13
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# JImageHash
[](https://travis-ci.org/KilianB/JImageHash)
[](https://github.com/KilianB/JImageHash/blob/master/LICENSE)
[](https://bintray.com/kilianb/maven/JImageHash/_latestVersion)
[](https://www.codacy.com/app/KilianB/JImageHash?utm_source=github.com&utm_medium=referral&utm_content=KilianB/JImageHash&utm_campaign=Badge_Grade)
JImageHash is a performant perceptual image fingerprinting library entirely written in Java. The library returns a similarity score aiming to identify entities which are likely modifications of the original source while being robust variouse attack vectors ie. color, rotation and scale transformation.
> A perceptual hash is a fingerprint of a multimedia file derived from various features from its content. Unlike cryptographic hash functions which rely on the avalanche effect of small changes in input leading to drastic changes in the output, perceptual hashes are "close" to one another if the features are similar.
This library was inspired by _Dr. Neal Krawetz_ blog post "kind of like that" and incorporates several improvements. A comprehensive overview of perceptual image hashing can be found in this paper by Christoph Zauner.
## Maven - Bintray
The project is hosted on bintray and jcenter. Please be aware that migrating from one major version to another usually invalidates creatd hashes
````XML
jcenter
https://jcenter.bintray.com/
com.github.kilianB
JImageHash
3.0.0
com.h2database
h2
1.4.197
````
## Hello World
````Java
File img0 = new File("path/to/file.png");
File img1 = new File("path/to/secondFile.jpg");
HashingAlgorithm hasher = new PerceptiveHash(32);
Hash hash0 = hasher.hash(img0);
Hash hash1 = hasher.hash(img1);
double similarityScore = hash0.normalizedHammingDistance(hash1);
if(similarityScore < .2) {
//Considered a duplicate in this particular case
}
//Chaining multiple matcher for single image comparison
SingleImageMatcher matcher = new SingleImageMatcher();
matcher.addHashingAlgorithm(new AverageHash(64),.3);
matcher.addHashingAlgorithm(new PerceptiveHash(32),.2);
if(matcher.checkSimilarity(img0,img1)) {
//Considered a duplicate in this particular case
}
````
## Examples
Below you can find examples of convenience methods used to get fast results. Further examples are provided in the examples folder explain how to choose
and optimize individual algorithms on your own.
| Algorithm | Feature | Notes |
| AverageHash | Average Luminosity | Fast and good all purpose algorithm |
| AverageColorHash | Average Color | Version 1.x.x AHash. Usually worse off than AverageHash. Not robust against color changes |
| DifferenceHash | Gradient/Edge detection | A bit more robust against hue/sat changes compared to AColorHash |
| Wavelet Hash | Frequency & Location | Feature extracting by applying haar wavlets multiple times to the input image. Detection quality better than inbetween aHash and pHash. |
| PerceptiveHash | Frequency | Hash based on Discrete Cosine Transformation. Smaller hash distribution but best accuracy / bitResolution. |
| MedianHash | Median Luminosity | Identical to AHash but takes the median value into account. A bit better to detect watermarks but worse at scale transformation |
| AverageKernelHash | Average luminosity | Same as AHash with kernel preprocessing. So far usually performs worse, but testing is not done yet. |
| Rotational Invariant |
| RotAverageHash | Average Luminosity | Rotational robust version of AHash. Performs well but performance scales disastrous with higher bit resolutions . Conceptual issue: pixels further away from the center are weightend less. |
| RotPHash | Frequency | Rotational invariant version of pHash using ring partition to map pixels in a circular fashion. Lower complexity for high bit sizes but due to sorting pixel values usually maps to a lower normalized distance. Usually bit res of >= 64bits are preferable |
| Experimental. Hashes available but not well tuned and subject to changes |
| HogHash | Angular Gradient based (detection of shapes?) | A hashing algorithm based on hog feature detection which extracts gradients and pools them by angles. Usually used in support vector machine/NNs human outline detection. It's not entirely set how the feature vectors should be encoded. Currently average, but not great results, expensive to compute and requires a rather high bit resolution |
### Version 3.0.0 Image clustering
Image clustering with fuzzy hashes allowing to represent hashes with probability bits instead of simple 0's and 1's

### Algorithm benchmarking
See the wiki page on how to test differet hashing algorithms with your set of images