Compare Two Images for Similarity in JavaScript

Cloudmersive
1 min readApr 22, 2021

Attempting to sort through datasets searching for duplicates or finding a visually similar set of images can be an unpleasant and tedious process. To simplify your search, you can use an API in JavaScript to generate an image similarity score between two images. The API leverages Deep Learning to create the score, which will between 0 and 1; values closer to 1 indicate greater similarity.

To start things off, we will run this command to install the jQuery library:

bower install jquery

With the installation complete, we are ready to call our image comparison function:

var form = new FormData();
form.append("baseImage", fileInput.files[0], "file");
form.append("comparisonImage", fileInput.files[0], "file");
var settings = {
"url": "https://api.cloudmersive.com/image/recognize/similarity/compare",
"method": "POST",
"timeout": 0,
"headers": {
"recognitionMode": "<string>",
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});

Your similarity score will be ready in a matter of seconds. Visit the Cloudmersive website to retrieve your free API key and gain access to 800 monthly calls across our library of APIs.

--

--

Cloudmersive

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