|
Hi, I'm currently stuck with understanding why my comparing script doesn't work as expected, so I wanted to save a difference between two images like it shown here -> https://stackoverflow.com/questions/40360921/comparing-two-images-using-imagemagick-and-c-sharp However, when I try to use this code in my script, it doesn't work as expected, showing "Argument type 'ImageMagick.MagickImage' is not assignable to parameter type 'ImageMagick.Channels'". Hence why I'm asking how to save the difference between two images here's the code snippet that I currently tried to use
using ImageCompare.Image;
List<string> originals = [];
List<string> copies = [];
string[] fileList = Directory.GetFiles(@"C:\test\unsorted");
foreach(var firstImage in fileList) {
if (copies.Contains(firstImage))
continue;
foreach(var secondImage in fileList) {
if (firstImage == secondImage)
continue;
if (Image.IsSimilar(firstImage, secondImage)) {
if(!originals.Contains(firstImage))
originals.Add(firstImage);
if (!copies.Contains(secondImage))
copies.Add(secondImage);
Console.WriteLine($"{firstImage} is original and {secondImage} is a copy");
}
}
}
foreach (var image in originals)
Console.WriteLine($"Original: {image}");
foreach(var image in copies)
Console.WriteLine($"Copy: {image}");
using ImageMagick;
namespace ImageCompare.Image
{
public class Image
{
public static bool IsSimilar(string firstImage, string secondImage)
{
using var img1 = new MagickImage(firstImage);
using var img2 = new MagickImage(secondImage);
using var imgDiff = new MagickImage();
double diff = img1.Compare(img2, new ErrorMetric(), imgDiff);
imgDiff.Write(@"C:\test\Diff-Image1-Image2.jpg");
return false;
}
}
}I'd be very happy if someone could help me, so thank you everyone in advance |
Answered by
dlemstra
Mar 6, 2026
Replies: 1 comment 2 replies
|
The api has changed over the years. You will need to use this overload instead: using var imgDiff = img1.Compare(img2, ErrorMetric.RootMeanSquared, out var diff); |
2 replies
Answer selected by
tadatomix
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

The api has changed over the years. You will need to use this overload instead: