Question about image comparison using Magick++

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
michellexuf
Posts: 2
Joined: 2013-03-07T11:47:00-07:00
Authentication code: 6789

Question about image comparison using Magick++

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Question about image comparison using Magick++

Post 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().
michellexuf
Posts: 2
Joined: 2013-03-07T11:47:00-07:00
Authentication code: 6789

Re: Question about image comparison using Magick++

Post 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.
Post Reply