Skip to content

Instantly share code, notes, and snippets.

@hideack
Created June 6, 2020 02:33
Show Gist options
  • Select an option

  • Save hideack/00a343d11d3d3b2a6cf4242570d69cd5 to your computer and use it in GitHub Desktop.

Select an option

Save hideack/00a343d11d3d3b2a6cf4242570d69cd5 to your computer and use it in GitHub Desktop.
var pHash = require("phash");
var samples = [
"samples/lena.jpg",
"samples/lena-small.jpg",
"samples/lena-sepia.jpg",
"samples/lena-mosaic.jpg",
"samples/lena-cut.jpg",
"samples/lena-cut2.jpg",
"samples/lena-horizonal-flip.jpg"
];
var hash = [];
samples.forEach(function(sample) {
hash.push(pHash.imageHashSync(sample));
});
for(var i=0; i<hash.length; i++) {
console.log("Hash No." + i + " : " + parseInt(hash[i]).toString(16));
console.log("File:" + samples[i]);
console.log("Haming distance (vs hash[0]) = " + pHash.hammingDistance(hash[0], hash[i]));
console.log("-----");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment