Zefirrat.ImageComparer 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Zefirrat.ImageComparer --version 1.0.0                
NuGet\Install-Package Zefirrat.ImageComparer -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zefirrat.ImageComparer" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Zefirrat.ImageComparer --version 1.0.0                
#r "nuget: Zefirrat.ImageComparer, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Zefirrat.ImageComparer as a Cake Addin
#addin nuget:?package=Zefirrat.ImageComparer&version=1.0.0

// Install Zefirrat.ImageComparer as a Cake Tool
#tool nuget:?package=Zefirrat.ImageComparer&version=1.0.0                

Zefirrat.ImageComparer

Recognition of similar or same images, with varying degrees of accuracy.
For example, for images with noise, the similarity of compressed images and the original ones, to search for the original image by its compressed copy, to search for images with small changes or distortions.

Test demonstrations

First image for compare (source):

image

Comparing with compressed:

image

Result:

Accuracy: VeryLow
    Similar: True ✔      
    Equal: True ✔        
-------------------------
Accuracy: Low
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: Medium
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: High
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: VeryHigh       
    Similar: False ✖
    Equal: False ✖
-------------------------

Added transparent drawing at right bottom corner:

image

Result:

Accuracy: VeryLow
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: Low
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: Medium
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: High
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: VeryHigh
    Similar: False ✖
    Equal: False ✖
-------------------------

Added few red curves:

image

Result:

Accuracy: VeryLow
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: Low
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: Medium
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: High
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: VeryHigh
    Similar: False ✖
    Equal: False ✖
-------------------------

Added more red curves:

image

Result:

Accuracy: VeryLow
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: Low
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: Medium
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: High
    Similar: False ✖     
    Equal: False ✖       
-------------------------
Accuracy: VeryHigh       
    Similar: False ✖
    Equal: False ✖
-------------------------

Added mush more red curves:

image

Result:

Accuracy: VeryLow
    Similar: True ✔      
    Equal: False ✖       
-------------------------
Accuracy: Low
    Similar: False ✖     
    Equal: False ✖       
-------------------------
Accuracy: Medium
    Similar: False ✖     
    Equal: False ✖       
-------------------------
Accuracy: High
    Similar: False ✖     
    Equal: False ✖       
-------------------------
Accuracy: VeryHigh
    Similar: False ✖
    Equal: False ✖
-------------------------

Installation

PM > Install-Package Zefirrat.ImageComparer

Usage

Base

    var imageComparer = new ImageComparer();

    using var image1 = Image.Load("../../../../Test_Images/test_image_source.png");
    using var image2 = Image.Load("../../../../Test_Images/test_image_source_compressed.jpg");

    var similar = imageComparer.AreSimilar(image1, image2);
    var equal = imageComparer.AreEqual(image1, image2);

Accuracy options

Выше значение - выше допускаемый разброс.

public cllass ImageComparer
{
    // ...
        public static class AccuracyValues
        {
            public const byte VeryHigh = 1;
            public const byte High = 20;
            public const byte Medium = 50;
            public const byte Low = 90;
            public const byte VeryLow = byte.MaxValue;
        }
}
    var imageComparer = new ImageComparer(ImageComparerOptions.AccuracyValues.VeryHigh);

Dependency Injection

In Configure:

    serviceCollection.AddImageComparer

And then request as interface:

public YourControllerConstructor(IImageComparer imageComparer)
{
    _imageComparer = imageComparer;
}

Explanation:

Inspired by the work on the "Manhattan distance" algorithm, which was based on calculating the distance between similar pixels, and based on this value, the probability of similarity of images was compared by the mean square deviation (standard deviation).

I took from this approach, the work with the mean square deviation (standard deviation).

Prepare:

  • To begin with, all images are resized to 16x16.
  • Then we take the rgba pixel values as coordinate values
  • Convert pixels to vectors
  • We take the lengths of the vectors
  • We get an array of vector lengths for each image being compared

For equality:

  • Comparison of the vector difference of each pixel with an acceptable discrepancy

For similarity:

  • Getting the quadratic deviation (standard deviation) between the vectors for each image, and the sum of all vectors
  • The difference between the total deviation and the deviation for each image should not exceed the allowable discrepancy
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Zefirrat.ImageComparer:

Package Downloads
Zefirrat.ImageComparer.AspNet.Di

See https://github.com/Zefirrat/ImageComparer

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 216 12/14/2023
1.1.0.1 192 12/13/2023
1.1.0.1-pre1 111 12/13/2023
1.1.0 203 12/12/2023
1.1.0-pre2 121 12/11/2023
1.1.0-pre16 104 12/12/2023
1.0.0.4 133 12/6/2023
1.0.0.3 427 12/6/2023
1.0.0.2 137 12/6/2023
1.0.0.1 193 12/6/2023
1.0.0 234 12/6/2023