Example UsageOption Summary

Use the compare program to mathematically and visually annotate the difference between an image and its reconstruction. See Command Line Processing for advice on how to structure your compare command or see below for example usages of the command.

Example Usage

We list a few examples of the compare command here to illustrate its usefulness and ease of use. To get started, lets compare an image to one thats been sharpened:

convert rose.jpg -sharpen 0x1 reconstruct.jpg
compare rose.jpg reconstruct.jpg difference.png
compare -compose src rose.jpg reconstruct.jpg difference.png
    rose rose ==> rose

The red areas of the difference image emphasizes (highlight) pixels that are affected by the image sharpening, whereas white de-emphasizes (lowlight) pixels that are untouched by the sharpening process.

In addition to the visual interpretation of the difference in an image and its reconstruction, we report a mathematical measure of the difference:

-> compare -verbose -metric mae rose.jpg reconstruct.jpg difference.png
Image: rose.jpg
 Channel distortion: MAE
  red: 2282.91 (0.034835)
  green: 1853.99 (0.0282901)
  blue: 2008.67 (0.0306503)
  all: 1536.39 (0.0234439)

Or, if you just want the red channel distortion, use this command:

-> compare -channel red -metric PSNR rose.jpg reconstruct.jpg difference.png

Or, if you just want the overall image distortion, use this command:

-> compare -metric PSNR rose.jpg reconstruct.jpg difference.png

If the reconstructed image is a subimage of the image, the compare program returns the best match offset. In addition, it returns a similarity image such that an exact match location is completely white and if none of the pixels match, black, otherwise some gray level in-between:

-> compare -metric RMSE -subimage-search logo.png wizard.jpg similarity.gif
85.05 (0.00129778) @ 353,157

You can find additional examples of using compare in Graphics from the Command Line. Further discussion is available in More Graphics from the Command Line and Examples of ImageMagick Usage.

The compare program returns 2 on error otherwise 0 if the images are similar or 1 if they are dissimilar.

Option Summary

The compare command recognizes these options. Click on an option to get more details about how that option works.

Option Description
-alpha on, activate, off, deactivate, set, opaque, copy", transparent, extract, background, or shape the alpha channel
-authenticate value decrypt image with this password
-channel type apply option to select image channels
-colorspace type set image colorspace
-compose operator set image composite operator
-decipher filename convert cipher pixels to plain
-debug events display copious debugging information
-define format:option define one or more image format options
-density geometry horizontal and vertical density of the image
-depth value image depth
-dissimilarity-threshold value maximum distortion for (sub)image match (default 0.2)
-encipher filename convert plain pixels to cipher pixels
-extract geometry extract area from image
-fuzz distance colors within this distance are considered equal
-help print program options
-highlight-color color emphasize pixel differences with this color
-identify identify the format and characteristics of the image
-interlace type type of image interlacing scheme
-limit type value pixel cache resource limit
-log format format of debugging information
-lowlight-color color de-emphasize pixel differences with this color
-metric type measure differences between images with this metric
-profile filename add, delete, or apply an image profile
-quality value JPEG/MIFF/PNG compression level
-quantize colorspace reduce image colors in this colorspace
-quiet suppress all warning messages
-regard-warnings pay attention to warning messages.
-respect-parentheses settings remain in effect until parenthesis boundary.
-sampling-factor geometry horizontal and vertical sampling factor
-seed value seed a new sequence of pseudo-random numbers
-set attribute value set an image attribute
-similarity-threshold value minimum distortion for (sub)image match (default 0.0)
-size geometry width and height of image
-subimage-search search for subimage
-synchronize synchronize image to storage device
-taint mark the image as modified
-transparent-color color transparent color
-verbose print detailed information about the image
-version print version information
-virtual-pixel method access method for pixels outside the boundaries of the image