Compare Image Similarity in C#

Whether you have a large company that’s looking to organize their images more effectively, or a video app that’s attempting to locate similar videos, using Deep Learning AI to gauge image similarity can make the process a whole lot easier. The following API leverages that AI to compare two images and generate an image similarity score between 0 and 1. There is an option to set the recognition mode to Basic, Normal, and Advances as well, with the default being Normal.

Now to use the API in C#, we will run this command to install the .NET Framework SDK:

Install-Package Cloudmersive.APIClient.NET.ImageRecognition -Version 3.0.5

Next, we will call the comparison function with the following code:

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.ImageRecognition.Api;
using Cloudmersive.APIClient.NET.ImageRecognition.Client;
using Cloudmersive.APIClient.NET.ImageRecognition.Model;
namespace Example
{
public class RecognizeSimilarityCompareExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");


var apiInstance = new RecognizeApi();
var baseImage = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Image file to compare against. Common file formats such as PNG, JPEG are supported.
var comparisonImage = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Image to compare to the base image.
var recognitionMode = recognitionMode_example; // string | Optional, specify the recognition mode; possible values are Normal, Basic and Advanced. Default is Normal. (optional)
try
{
// Compare two images for similarity
byte[] result = apiInstance.RecognizeSimilarityCompare(baseImage, comparisonImage, recognitionMode);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling RecognizeApi.RecognizeSimilarityCompare: " + e.Message );
}
}
}
}

And that’s it! Visit the Cloudmersive website to retrieve your API key and register for a free account; this will give you access to 800 calls/month across all of our APIs.

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