How to Compare Images for Similarity in Node.JS

Need to compare images for similarity, but don’t want to deal with manually muddling through image data? We have you covered. The following API can be run in Node.JS to generate an image similarity score using Deep Learning; the score will be between 0 and 1, with values closer to 1 indicating greater similarity. Depending on your business need, this can be helpful for both organizing and/or ranking images.

Let’s get started by running this command to install the SDK:

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

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

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

Once the installation is complete, we will input the base image, comparison image, recognition mode (optional — default is normal), and API key into 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 baseImage = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Image file to compare against. Common file formats such as PNG, JPEG are supported.var comparisonImage = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Image to compare to the base image.var opts = {
'recognitionMode': "recognitionMode_example" // String | Optional, specify the recognition mode; possible values are Normal, Basic and Advanced. Default is Normal.
var callback = function(error, data, response) {
if (error) {
} else {
console.log('API called successfully. Returned data: ' + data);
apiInstance.recognizeSimilarityCompare(baseImage, comparisonImage, opts, callback);

Your result will be delivered immediately — no stress needed. If you need to retrieve your API key, head over to the Cloudmersive website to register for a free account; this will give you access to 800 monthly calls as well!

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