Calculate the Similarity Between Image Hashes in Node.JS

Considering the amount of replication threats targeted at online multimedia these days, perceptual image hashing has presented itself as a pivotal solution. The functions of perceptual image hashing are aimed at generating a hash value for the multimedia, in this case an image, that can in turn be used to compare and match images in a database. To avoid the occasionally complex calculations and research that accompany this process, we will demonstrate how to use the following API in Node.JS to compute the Hamming Distance between two perceptual image hashes.

First, we will run this command to install the Node.JS client:

npm install cloudmersive-image-api-client --save

Or you can add this snippet to your package.json:

"dependencies": {
"cloudmersive-image-api-client": "^1.3.4"

Now we’re ready to call the function with the following code:

var CloudmersiveImageApiClient = require('cloudmersive-image-api-client');
var defaultClient = CloudmersiveImageApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveImageApiClient.RecognizeApi();var request = new CloudmersiveImageApiClient.ImageSimilarityHashDistanceRequest(); // ImageSimilarityHashDistanceRequest |var callback = function(error, data, response) {
if (error) {
} else {
console.log('API called successfully. Returned data: ' + data);
apiInstance.recognizeSimilarityHashDistance(request, callback);

To ensure the process runs smoothly, you will only need to input the two image hashes and your API key. If you don’t already have an API key, you can retrieve one by registering for a free account on the .



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.