laurent
laurent

Reputation: 90756

Ignoring differences in brightness with ImageMagick compare tool

I'm using compare to find if something has changed between two photos. It generally works well, except when the room suddenly becomes a bit darker or brighter. So I'm wondering - is it possible to ignore the difference in brightness when running compare?

So far I'm using the command below:

compare -fuzz 15% -metric ae /path/to/image1.jpg /path/to/image2.jpg /path/to/diff.png

For example, for this set of images, I would get approximately 5% difference, while I would like to bring it below 1% or even less if possible.

Any suggestion?

Upvotes: 0

Views: 392

Answers (1)

Glenn Randers-Pehrson
Glenn Randers-Pehrson

Reputation: 12455

You could normalize the two images, then compare those:

convert VaoZF.jpg -normalize image1.ppm
convert whgkn.jpg -normalize image2.ppm
compare -fuzz 15% -metric ae image1.ppm image2.ppm diff.png

You can get the difference metric with a single command and without making any temporary files:

magick \( VaoZF.jpg -normalize \) \( whgkn.jpg -normalize \) \
      -fuzz 15% -metric ae -compare -format "%[distortion]" info:

If you are on Windows, use "(" and ")" instead of "\(" and "\)" and use a "^" instead of a "\" for suppressing the line break, and replace "%" with "%%".

Upvotes: 1

Related Questions