You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Hash Algorithms
This project implements the following algorithms:
AverageHash by Dr. Neal Krawetz. Check his blog/article here;
PerceptualHash also by Dr. Neal Krawetz.
DifferenceHash by David Oftedal with minor improvements of Dr. Neal Krawetz. More information can be found here or here.
Credits
This project uses the ImageSharp library for image processing;
varhashAlgorithm=newAverageHash();// or one of the other available algorithms:// var hashAlgorithm = new DifferenceHash();// var hashAlgorithm = new PerceptualHash();stringfilename="your filename";usingvarstream=File.OpenRead(filename);ulongimageHash=hashAlgorithm.Hash(stream);
Note that to calculate the image similarity, both image hashes should have been calculated using the same hash algorihm.
// calculate the two image hashesulonghash1=hashAlgorithm.Hash(imageStream1);ulonghash2=hashAlgorithm.Hash(imageStream2);doublepercentageImageSimilarity=CompareHash.Similarity(hash1,hash2);