KilianB / JImageHash

Perceptual image hashing library used to match similar images
MIT License
407 stars 83 forks source link

Add ColorMomentsHash #70

Open ArrowM opened 1 year ago

ArrowM commented 1 year ago

Modeled after https://github.com/chongwar/image-sort/blob/d19d990809c3caf5d4219aa3497df8ca760e0fcc/_hash.py#L83

This PR needs more work before it's ready to merge, but I think I'm done working on it. I'm leaving this PR in-case someone else wants to run with it.

Completed

MomentsHash.java

#distance() works similarly to hammingDistance(), however distance() returns a double. Internally it works very differently, so the class does not extend Hash, nor is it compatible with other Hash objects.

ColorMomentsHash.java

#hash2(File imageFile) calculates a MomentsHash. #hash2(File imageFile, int[] weights) is similar to the previous hash2, but allows the weights of hue, saturation, and value to be specified.

Incomplete

Since our hash needs to return a MomentsHash instead of a normal Hash, this class should not extend HashingAlgorithm as it does now because it can't use #hash(). (I tried to get this alg to working with hamming distance but had no success). Instead it either needs to have stuff copied from HashingAlgorithm directly into its class, or a new class needs to be added that both ColorMomentsHash and HashingAlgorithm can extend.

Other notes

Despite not matching the formatting of the other algs, ColorMomentsHash does seem to work and its performance is in the ballpark of the others.