Page 1 of 1

Question about image comparison using Magick++

Posted: 2013-03-07T12:07:18-07:00
by michellexuf
Hello,

I'm doing the comparison between two images. First I tested the result using command line, which worked well.

convert $image1 -crop $area - | compare -dissimilarity-threshold 1 -fuzz 25% -metric AE $image2 -null: 2>result.txt

Then I need to do the same thing using Magick++. Here is what I have done.

1) Read the first image into the image class.
Image1.read("image1name.jpg")

2) Did crop on the first image.
image1.crop( Geometry(width, height, xOffset, yOffset) )

3) Set fuzz as 25%
image1.colorFuzz(25*QuantumRange/100)

4) Did comparison
image1.compare("image2name.jpg")

So my questions are:
1) How to set the "-dissimilarity-threshold" and "-metric" as the command line did?
2) How to output the comparison value to a *.txt file as the command line did?

I didn't find the related information in the tutorail or the forum.
I appreciate any related information.

Re: Question about image comparison using Magick++

Posted: 2013-03-07T16:59:04-07:00
by magick
compare() measures the difference between two images and return true if they are identical. To use a dissimilarity threshold you'll need to use the MagickCore method SimilarityMetricImage(). Call it from Magick++ with MagickCore::SimilarityMetricImage().

Re: Question about image comparison using Magick++

Posted: 2013-03-13T18:56:24-07:00
by michellexuf
Hello Mr. Magick,

Thanks for your reply.

What I'm doing is comparing two images with the setting of error metric, dissimilarity threshold, and colorFuzz.

The metric is "AbosoluteError", and the output should be a value which means the different pixel numbers between two images.

I've got the correct results by command line:

convert $image1 -crop $area - | compare -dissimilarity-threshold 1 -fuzz 25% -metric AE $image2 -null: 2>result.txt

Now I'm using Magick++.

As you suggested, I tried the MagickCore::SimilarityMetricImage in my Magick++ code, but it does't work. I got the following error.

error: cnnnot convert 'Magick::Image*' to 'MagickCore::Image* (aka MagickCore::_Image*)' for argument '1' to 'MagickCore::Image* MagickCore::SimilarityMetricImage(image1, image2......)'

image1 and image2 are defined as:
Magick::Image image1, image2;

I used methods of Magick++ processing image1 and image2 before SimilarityMetricImage.

Could you please give me more information about image comparison with the specific setting?

I appreciate your help.