62

You can compare two text files very easy with diff and even better with meld:

example meld

If you use diff for images, you get an example like this:

$ diff zivi-besch.tif zivildienst.tif 
Binary files zivi-besch.tif and zivildienst.tif differ

Here is an example:

Original from http://commons.wikimedia.org/wiki/File:Tux.svg

Original image

Edited:

edited

I've added a white background to both images and applied GIMPs "Difference" filter to get this:

difference

It is a very simple method how a diff could work, but I can imagine much better (and more complicated) ones.

Do you know a program which works for images like meld does for texts?

(If a program existed that could give a percentage (0% the same image - 100% the same image) I would also be interested in it, but I am looking for one that gives me visual hints where differences are.)

72

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.

| improve this answer | |
  • Is there a way to merge? Or patch the difference to the original to get the target? – CMCDragonkai May 19 '16 at 13:58
  • @CMCDragonkai ImageMagick is very powerful. I don't know the exact invocation, but you can filter and chain operations on images, and create new ones. So I am pretty sure you could "merge" with an ImageMagick script. – HRJ Jul 20 '16 at 10:17
  • 1
    imagemagick is really a magic ! – Brain90 Nov 24 '16 at 16:30
  • How about using compare with AE, but without generating a difference image? – user643722 Nov 19 '18 at 17:23
6

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.
| improve this answer | |
5
  1. There is command idiff in package openimageio-tools.
  2. There is command perceptualdiff (package perceptualdiff).
  3. There is command uprightdiff (package uprightdiff).
| improve this answer | |
0

I ended up with the following:

~/.gitconfig

Append

[diff "image"]
    command = simple-imagediff

simple-imagediff

I've added the following to ~/.local/bin/simple-imagediff:

#!/usr/bin/env python

# Simple Image Diffs
# ==================
#
# How to Install
# --------------
#
# Download the script somewhere on $PATH as 'simple-imagediff' with +x:
#
# $ cd ~/bin
# $ wget -O simple-imagediff https://raw.github.com/gist/1716699/simple-imagediff.py
# $ chmod +x simple-imagediff
#
# Prerequisites
# -------------
#
# The script should work out-of-the box on Ubuntu 11.10. On other OS'es you may
# need to install PIL and Gtk3.
#
# Git Setup
# ---------
#
# In ~/.gitconfig, add:
#
# [diff "image"]
#   command = simple-imagediff
#
# In your project, create .gitattributes file and add (this enables the custom
# diff tool above):
#
# *.gif diff=image
# *.jpg diff=image
# *.png diff=image
#
# Try It
# ------
#
# $ git diff path/to/file.png
#
# NOTE: file.png must be versioned and the working copy must be different.

import os
import sys

import Image

from gi.repository import Gdk, Gtk


class SimpleImageDiffWindow(Gtk.Window):
    def __init__(self, left, right):
        Gtk.Window.__init__(self,
                            title="Simple Image Diff (%s, %s)" % (left, right))
        self.set_default_size(640, 480)
        align = Gtk.Alignment()
        align.set_padding(10, 10, 10, 10)
        box = Gtk.HBox(homogeneous=True, spacing=10)
        box.add(self._create_image_box(left))
        box.add(self._create_image_box(right))
        align.add(box)
        self.add(align)
        self.resize(1, 1)
        self.set_position(Gtk.WindowPosition.CENTER)

    def _create_image_box(self, image_file):
        box = Gtk.VBox(spacing=10)
        frame = Gtk.Frame()
        image = Gtk.Image()
        image.set_from_file(image_file)
        title = Gtk.Label(label="W: %dpx  |  H: %dpx" %
                          Image.open(image_file).size)
        frame.add(image)
        box.pack_start(frame, True, True, 0)
        box.pack_end(title, False, False, 10)
        return box


def _halt(message, code):
    sys.stderr.write("[ERROR] %s\n" % message)
    sys.exit(0 << code)


def _verify_file_exists(target):
    if not os.path.exists(target):
        _halt("The file '%s' does not exists." % target, 2)

if __name__ == '__main__':
    if len(sys.argv) < 3:
        _halt('Not enough arguments.', 1)
    _verify_file_exists(sys.argv[1])
    _verify_file_exists(sys.argv[2])
    app = SimpleImageDiffWindow(sys.argv[1], sys.argv[2])
    app.connect('delete-event', Gtk.main_quit)
    app.show_all()
    Gtk.main()
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.