Skip to content

nima-ap/ImageSharp.Compare

 
 

Repository files navigation

ImageSharpCompare

Compares images

.github/workflows/dotnet.yml Nuget Donate

Inspired by the image compare feature "Visual verification API" of TestApi this code supports comparing images by using a tolerance mask image. That tolerance mask image is a valid image by itself and can be manipulated.

ImageSharpCompare focus on os agnostic support and therefore depends on SixLabors.ImageSharp.

NOTE: for now the comparer will only work with RGB components and totally ignores Alpha-channell.

Example simple show cases

bool isEqual = ImageSharpCompare.ImagesAreEqual("actual.png", "expected.png");

// calcs MeanError, AbsoluteError, PixelErrorCount and PixelErrorPercentage
ICompareResult calcDiff = ImageSharpCompare.CalcDiff("actual.png", "expected.png");

Example show case allowing some tolerated diff

Imagine two images you want to compare, and want to accept the found difference as at state of allowed difference.

Reference Image

actual image

Actual Image

actual image

Tolerance mask image

using "compare.CalcDiff" you can calc a diff mask from actual and reference image

Example - Create difference image

using (var fileStreamDifferenceMask = File.Create("differenceMask.png"))
using (var maskImage = ImageSharpCompare.CalcDiffMaskImage(pathPic1, pathPic2))
    SixLabors.ImageSharp.ImageExtensions.SaveAsPng(maskImage, fileStreamDifferenceMask);

differenceMask.png

Example - Compare two images using the created difference image. Add white pixels to differenceMask.png where you want to allow difference.

var maskedDiff = ImageSharpCompare.CalcDiff(pathPic1, pathPic2, "differenceMask.png");
Assert.That(maskedDiff.AbsoluteError, Is.EqualTo(0));

About

Adds compare features on top of ImageSharp

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%