Compare image similarity using hashing algorithms
masterThe library provides several hashing algorithms to generate perceptual hashes from images. Once hashes are generated, you can use the Distance method to calculate the Hamming distance between them; a lower distance indicates higher similarity.
Supported algorithms include:
AverageHashDifferenceHashPerceptionHash(enhanced in v1.1.0)ExtAverageHash(Extended Average Hash with custom width/height)ExtDifferenceHash(Extended Difference Hash)ExtPerceptionHash(Extended Perception Hash)
Note: Ext versions allow you to specify the width and height of the hash bit size.
// Example: Comparing two images using AverageHash
img1, _ := jpeg.Decode(file1)
img2, _ := jpeg.Decode(file2)
hash1, _ := goimagehash.AverageHash(img1)
hash2, _ := goimagehash.AverageHash(img2)
distance, _ := hash1.Distance(hash2)
fmt.Printf("Distance between images: %v\n", distance)