hannes ach
hannes ach

Reputation: 17733

compare an image using ImageMagick and only get result true/false 0/1

We use a git repo for screenshots and always the images are marked changed by git, but with apply fuzz, there are no changes.

I use this script to compare images

do_compare()
{
     compare $color_flag $fuzz_flag $backgroundcolor_flag "$f1" "$f2" png:- | \
        montage -geometry +4+4 $backgroundcolor_flag "$f1" - "$f2" png:- >"$destfile" 2>/dev/null || true
}

but I want only know if there is a change in the image, with respect the fuzz, or not.

Does someone has an idea how to do so ?

Upvotes: 0

Views: 1258

Answers (1)

fmw42
fmw42

Reputation: 53089

You can do that in command line ImageMagick on Unix using

compare -metric ae -fuzz XX% image1 image2 null: 2>&1


-metric ae will return the number of pixels that do not match. So if the result is 0, then it matches perfectly within the specified -fuzz value.

For example, testing with fuzz = 0:

XX=0
test=`compare -metric ae -fuzz $XX% lena.png lena.jpg null: 2>&1`
if [ "$test" = "0" ]; then
echo "match"
else
echo "no match"
fi

no match


Testing with fuzz = 10%:

XX=10
test=`compare -metric ae -fuzz $XX% lena.png lena.jpg null: 2>&1`
if [ "$test" = "0" ]; then
echo "match"
else
echo "no match"
fi

match

Upvotes: 3

Related Questions