Personal tools
You are here: Home / cmgui / Wiki / Comparing two images
Navigation
Log in


Forgot your password?
 

Comparing two images

The compare script

A quick method for comparing two files is to use the image magick compare script. You can specify an ouput image which will show the areas which are different and you can also specify various metrics to get a single value which is a measurement of the difference between the files

compare -metric AE SigmoidImageFilter.png SigmoidImageFilterCmgui.png difference.png

If you open up difference.png (using display or gimp) a greyed out version of the image is shown with the areas of difference highlighted in red.

See http://www.imagemagick.org/script/compare.php for more info on the use of compare.

Using Gimp

Another method to visually compare two images to see if they look the same is as follows:

  • Open the first image using gimp
  • Right click on the first image and select 'File->Open as layer'
  • Open the layer dialog (Ctrl+L or through the Dialogs menu)
  • Toggle the visibility of the layers by clicking on the eye icons. You should be able to determine whether the images look identical by switching the visibility of one layer on and off
  • A further test is to select the mode for one layer to difference. If there is no difference between the images the layer should now appear completely black.

Octave

Octave can be used to read images into arrays, which means you can easily manipulate and view the arrays to determine information about the difference between the images. Here is some Octave code I wrote to determine the number of pixels which differed by more than 1

baseline=imread('SigmoidImageFilter.png');
test=imread('SigmoideImageFilterCmgui.png');
greater_than_one = (baseline - test) > 1; % produces a matrix of 1s and 0s
pixels_greater_than_one = sum(sum(greater_than_one))

Example testing

There is a perl program called idiff which is used when testing examples. You can specify a threshold level (essentially a tolerance factor between 0 and 1) if an exact match is not required the threshold can be increased.

To use idiff check out the directory: '/examples/common/cmiss_type1/bin'