ImageMagick: How to Compare Two Images

Updated

Learn how to compare two images and find the differences using ImageMagick

ImageMagick: How to Compare Two Images

Before we start, make sure you have ImageMagick installed on your computer and your two images ready in a folder. If you don't have it yet, run this command:

brew install imagemagick

First, open your terminal and navigate to the folder that has your images. Both images need the same width and height. To see what changed, run this command:

magick compare image1.png image2.png diff.png

Just remember to replace image1.png and image2.png with your actual filenames. The compare tool saves a new image called diff.png, where everything that changed is marked in red on top of a faded copy of the original.

If you only want a number, run this command:

magick compare -metric RMSE image1.png image2.png null:

The -metric RMSE option gives a score, and null: means nothing gets saved. The number in brackets goes from 0, which means identical, up to 1, which means completely different. To make sure everything worked, run open diff.png and check the red area.

One more tip: add -fuzz 5% before the image names to ignore tiny differences, like JPEG compression noise.