Does "diff" exist for images?

Yes, such a program exists!

ImageMagick has the compare utility, which has several ways of comparing images.

To install it:

sudo apt-get install imagemagick imagemagick-doc

Comparing two images visually:

compare -compose src tux_orig.png tux_modified.png tux_difference.png

tux_orig.png & tux_modified.png

tux_orig.png tux_modified.png

Gives this image:

The image difference

Comparing two images via metrics:

There are also many ways to output the differences via some metrics, e.g.:

# compare -verbose -metric PSNR tux_orig.png tux_modified.png tux_difference.png
tux_orig.png PNG 200x232 200x232+0+0 8-bit sRGB 20.6KB 0.000u 0:00.000
tux_modified.png PNG 200x232 200x232+0+0 8-bit sRGB 22.2KB 0.010u 0:00.000
Image: tux_orig.png
  Channel distortion: PSNR
    red: 19.5485
    green: 19.5973
    blue: 19.6507
    alpha: 16.1568
    all: 18.4517
tux_orig.png=>tux_difference.png PNG 200x232 200x232+0+0 8-bit sRGB 12.3KB 0.030u 0:00.020

Some metric options:

AE     absolute error count, number of different pixels (-fuzz effected)
FUZZ   mean color distance
MAE    mean absolute error (normalized), average channel error distance
MEPP   mean error per pixel (normalized mean error, normalized peak error)
MSE    mean error squared, average of the channel error squared
NCC    normalized cross correlation
PAE    peak absolute (normalize peak absolute)
PSNR   peak signal to noise ratio
RMSE   root mean squared (normalized root mean squared)

There are many ways to compare images, see ImageMagicks section on compare for further methods.


This question was ask back in 2012, and it's 2017. We now have the non-open-source program Beyond Compare to compare images, and it integrates into Nautilus. We have also had Geeqie all along for finding similar images throughout a directory structure (recursively).

I. Finding Image Differences With Beyond Compare

Click this link to download Beyond Compare .deb packages.

Install the package by going to the directory you downloaded the package too, and typing: sudo dpkg -i YourPackageName.deb which at this moment is called bcompare-4.2.2.22384_amd64.deb, so you would type: sudo dpkg -i bcompare-4.2.2.22384_amd64.deb

To complete the install and get the plugin to work in Nautilus, you will need to log out, and then back in, because Nautilus is running in the background even if you don't have it open.

Once it is installed and the plugin is working properly, you:

  1. Open Nautilus, and browse to the first image
  2. Right-click the first image to bring up the context menu, and select Select Left File for Compare/Merge
  3. Browse to the second image
  4. Right-click the second image, and select Compare to 'NameOfFirstImageFile' where NameOfFirstImageFile is the name of the file you selected in step 2.
  5. The images will then open up in Beyond Compare, and it will look something like this:

Beyond Compare Image Comparison

II. Finding Similar/Duplicate Images With Geeqie

  1. Install Geeqie by tying this into a terminal: sudo apt install geeqie
  2. Open Geeqie, and browse to the directory you want to scan.
  3. Right-click the name of the directory you want to scan and select Find duplicates... to just scan that directory, or select Find duplicates recursive... to scan that directory and all directories under it.

enter image description here

  1. Using the Compare by drop-down list in the lower left corner, you can choose to find duplicates by Checksum, by Filename, or by Similarity levels. The similarity feature is awesome if you have cropped, rotated, or resized images, you no longer need, as many of us acquire, when we crop/resize pictures to post on social media and such.

  1. There is command idiff in package openimageio-tools.
  2. There is command perceptualdiff (package perceptualdiff).
  3. There is command uprightdiff (package uprightdiff).