Wednesday, April 25, 2012

Image Comparison using Image Magick freeware.

In my previous blog post, I have demonstrated the quickest way to identify whether 2 images are identical or different using C#. In this blog post, I will show you how to check exactly the visual difference between 2 different images using Image Magick compare tool.

ImageMagick is a software suite to create, edit, compose, or convert bitmap images. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and B├ęzier curves. Here, I am going to demonstrate Compare utility of Image Magick.

Step 1: As a first step install Image Magick software which you can find in below link.

This will install the required compare.exe tool in below location
C:\Program Files\ImageMagick-x.x.x-xxx

Step 2: As a next step take 2 images which you want to compare. For example I have taken 2 bitmap images in which one has a text “Hello” and another one with “Hello World”.

Hello.bmp – Standard

HelloWorld.bmp – Image for Comparison

Step 3: Open command prompt and then type the command following below syntax

Command line Image Comparison using Compare.exe
Compare.exe –metric type InputImageFullPath1 InputImageFullPath2 DifferenceImageFullPath

C:\Program Files\ImageMagick-6.7.3-Q16>compare.exe -metric AE "D:\ImageComparisonTest\Hello.bmp" "D:\ImageComparisonTest\HelloWorld.bmp" "D:\ImageComparisonTest\DiffHelloWorld.bmp"

-metric {type} - measures the differences between images with this metric.
Ex: –metric AE - Here AE represents absolute error. This will report the standard error with the number of pixel counts that were actually masked in the difference output.
InputImageFullPath1 – Provide full path for the standard image.
InputImageFullPath2 – provide full path for the image which you want to compare with the standard image
DifferenceImageFullPath – Provide full path to save the difference output image.

Difference output:
7653 - Pixels have been masked in generating below difference image.

Here in the output image the difference is masked with red color.

This utility will be very much helpful in batch processing for comparing large set of images. For more information on the usage of compare utility refer below link

No comments:

Post a Comment