Compare Two Images for Similarity in JavaScript

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": "",
"method": "POST",
"timeout": 0,
"headers": {
"recognitionMode": "<string>",
"Content-Type": "multipart/form-data",
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
$.ajax(settings).done(function (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.

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