LinuxCommandLibrary

compare

Visually compare image differences

TLDR

View documentation for the original command

$ tldr magick compare
copy

SYNOPSIS

compare [options...] input-file reference-file [output-file]

PARAMETERS

-metric
    Difference metric: AE, MAE (default), MSE, MEPP, PAE, PSNR, RMSE, or others like NCC, SSIM.

-fuzz [%]
    Colors within this distance are ignored; e.g., 5% tolerates small variations.

-highlight-color
    Color for pixels above dissimilarity threshold (default red).

-lowlight-color
    Color for pixels below threshold (default blue).

-dissimilarity-threshold
    Threshold for highlight/lowlight (0-1 or percent).

-compose
    Composition operator for difference image (e.g., difference, add, subtract).

-channel
    Apply to specific channels: R, G, B, A, All, Default.

-depth
    Image depth (8-64 bits per pixel).

-verbose
    Print detailed metric info to stderr.

-quiet
    Suppress all output except errors.

-authenticate
    Decrypt images with password.

-limit
    Pixel cache resource limit (e.g., memory 256MiB).

+swap
    Swap input and reference images.

-sigmoidal {+-}
    Sigmoidal contrast for highlights/lowlights.

--
    End of options; treat rest as filenames.

DESCRIPTION

The compare command, part of the ImageMagick suite, mathematically and visually annotates differences between two similar images. It generates an output image where differing pixels are highlighted using specified colors, making it ideal for quality assurance, detecting tampering, or verifying image processing results.

By default, it uses the Mean Absolute Error (MAE) metric and highlights differences in red (highlights) on black (lowlights). Users can specify metrics like Absolute Error Count (AE), Mean Squared Error (MSE), Peak Signal-to-Noise Ratio (PSNR), or Root Mean Squared Error (RMSE) to quantify differences numerically, often printed to stderr.

Key features include fuzz factor for tolerating minor color variations, support for specific channels (e.g., RGB, Alpha), and composition operators to blend differences. Input images can be in any ImageMagick-supported format (PNG, JPEG, TIFF, etc.). The output is typically a difference image, but metrics can be used standalone with -metric and no output file.

Common use cases: compare orig.png modified.png diff.png creates a visual diff. It's lightweight for batch processing and integrates with scripts for automated image validation.

CAVEATS

Requires ImageMagick installation (not always default). Output file format inferred from extension; specify explicitly if needed. High-resolution images may consume significant memory. Numerical metrics approximate perceptual differences; use SSIM for structural similarity.

BASIC EXAMPLE

compare -metric RMSE photo1.jpg photo2.jpg NULL: prints RMSE without output image.
compare -fuzz 10% orig.png new.png -compose src diff.png.

METRIC OUTPUT

Stderr shows: image1.jpg Metrics: RMSE 0.123 (0.0004%) @ pixel 100x50 for precise error location.

HISTORY

Developed as part of ImageMagick (first released 1990 by John Cristy). compare introduced early for image QA; evolved with metrics like SSIM (2006). Now in ImageMagick 7 as magick compare, but standalone compare persists for compatibility.

SEE ALSO

magick(1), convert(1), identify(1), montage(1), display(1)

Copied to clipboard