LinuxCommandLibrary

compare

Visually compare image differences

TLDR

View documentation for the original command

$ tldr magick compare
copy

SYNOPSIS

compare [options] input_image1 input_image2 output_image

PARAMETERS

-metric type
    Specifies the error metric to be used for comparison. Common types include AE (Absolute Error), MSE (Mean Squared Error), PSNR (Peak Signal-to-Noise Ratio), SSIM (Structural Similarity Index), PAE (Peak Absolute Error), MAE (Mean Absolute Error), RMSE (Root Mean Squared Error), PerceptualHash.

-fuzz percentage
    Colors that are similar within this percentage are considered the same. Useful for ignoring minor variations due to compression or noise.

-highlight-color color
    Specifies the color used to highlight differences in the output image. For example, red, blue, or #FF0000.

-lowlight-color color
    Specifies the color used for pixels that are identical in the output image.

-compose operator
    Sets the composite operator to use when creating the difference image. Common operators include difference, blend, xor.

-verbose
    Prints detailed information about the comparison, including the calculated metric value, to standard output.

-subimage-search
    Compares a smaller 'subimage' against a larger 'target image' to find the best match. The output image will highlight the matched area.

-dissimilarity-threshold value
    Sets a threshold for marking pixels as different. Pixels with difference below this value are considered identical.

-help
    Displays a comprehensive list of command-line options.

DESCRIPTION

The compare command from the ImageMagick suite is a powerful utility designed to compare two images and generate a visual representation of their differences. It calculates the difference metric between the two input images, often highlighting the pixels that vary between them. This is particularly useful for quality assurance, detecting unintended changes in image processing pipelines, or analyzing how image transformations affect visual fidelity.

The output can be an image showing the exact pixels that differ, often overlaid or blended to emphasize the changes, or a numerical metric indicating the degree of difference. It supports various comparison metrics like Absolute Error (AE), Mean Squared Error (MSE), Peak Signal-to-Noise Ratio (PSNR), Structural Similarity Index (SSIM), and more, allowing for flexible analysis based on specific requirements.

CAVEATS

Requires ImageMagick: The compare command is part of the ImageMagick suite; it's not a standalone core Linux utility. Users must install ImageMagick to use it.

Image Formats: While ImageMagick supports a vast array of image formats, subtle differences in encoding or metadata between otherwise identical images can sometimes lead to unexpected comparison results.

Computational Cost: Comparing very large images can be computationally intensive and memory-consuming, especially with certain metrics or detailed difference visualization.

Metric Interpretation: Understanding the various comparison metrics (AE, MSE, PSNR, SSIM, etc.) is crucial for accurate interpretation of results. A low numerical difference doesn't always imply a visually identical image.

VISUAL OUTPUT

compare typically produces a new image that visually highlights the differences between the two input images. This is distinct from tools like cmp or diff which output textual differences.

NUMERICAL OUTPUT

Besides the visual difference image, compare can output a numerical difference metric (e.g., PSNR, AE) to standard output when used with the -verbose option and a -metric specified. This allows for automated scripting and quality control checks.

HISTORY

ImageMagick itself dates back to 1990. The compare utility has been a core component of ImageMagick almost since its inception, designed to help users and developers assess visual fidelity and detect unintended changes in image processing. Its capabilities have evolved with ImageMagick, incorporating new comparison metrics, improved performance, and support for a wider range of image formats and color spaces. It's widely used in web development, quality control, and scientific imaging for automated image verification.

SEE ALSO

convert(1), mogrify(1), identify(1), display(1), cmp(1), diff(1)

Copied to clipboard