Craig
Craig

Reputation: 18704

ImageMagick Sharp Compare too sensitive

I'm trying to compare two images. I made a copy of the original jpeg I am using, and drew a small line on it.

I then ran the code below, using the original and changed jpegs, and landed up with a very red.

static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        MagickNET.SetTempDirectory(@"C:\scratch");
        MagickImage oldImage = new MagickImage(@"C:\Users\Craig\Pictures\orig.jpg");
        MagickImage newImage = new MagickImage(@"C:\Users\Craig\Pictures\changed.jpg");

        newImage.Crop(oldImage.BaseWidth, oldImage.BaseHeight);

        using (MagickImage diffImage = new MagickImage())
        {
            double diff = oldImage.Compare(newImage, ErrorMetric.Absolute, diffImage);
            Console.WriteLine($"Diff is {diff}...");
            diffImage.Write(@"C:\Users\Craig\Pictures\diff.jpg");
            Console.ReadKey();
        }

    }

enter image description here

I think the issue is that, it's too accurate, and the jpeg is modified a little (lossy?). Is there a way to calm it down and look for larger changes? Because if you look at the image, bottom right, you can see a smiley face I drew (mouth and eyes only). Maybe 1.5cm right the bottom, and 1.5cm from the right.

I think the answer is 'Fuzz', but I cannot see how to apply this to my code.

Upvotes: 1

Views: 369

Answers (1)

fmw42
fmw42

Reputation: 53154

JPEG is a lossy compression and so just saving it changes the values. You should be doing this with PNG or TIFF not JPG. Nevertheless, you should be able to use -fuzz in ImageMagick command line compare. compare -fuzz 20% -metric rmse image1 image2 diffimage

Input1:

enter image description here

Input2:

enter image description here

Compare no fuzz:

compare -metric rmse lena.jpg lena2.jpg diffimage.png


enter image description here

Compare with fuzz:

compare -fuzz 20% -metric rmse lena.jpg lena2.jpg diffimage2.png


enter image description here

Sorry, I do not know the equivalent in other APIs.

Upvotes: 2

Related Questions