magick-compare
Visually compare images and report differences
TLDR
Compare two images
Compare two images using the specified metric
SYNOPSIS
magick compare [options] input_image reference_image [difference_image]
The command requires two input image paths and optionally an output path for the difference image. If difference_image is omitted, ImageMagick will typically display the difference image or output it to stdout, depending on the environment and other options.
PARAMETERS
-metric
Specifies the image comparison metric to be calculated (e.g., AE, MAE, MSE, PSNR, SSIM, RMSE). Metrics like AE (Absolute Error) count differing pixels, while PSNR measures image quality degradation.
-fuzz
Sets the color distance tolerance for considering two colors as the same. For example, '-fuzz 5%' allows for a 5% difference in color components before pixels are considered distinct.
-highlight-color
Defines the color used to highlight differing pixels in the output image (e.g., 'red', '#FF0000').
-lowlight-color
Specifies the color for pixels that are identical in both images, effectively 'masking' the similar areas.
-compose
Determines the composite operator to use when merging the difference image (e.g., 'Difference' to show absolute differences, 'Src' to show the input image with highlighted differences).
-subimage-search
Compares the entire first image against every possible offset of the second image, useful for finding a subimage within a larger one.
-dissimilarity-threshold
Pixels with a metric value below this threshold are not considered different, allowing for minor variations to be ignored.
-verbose
Enables verbose output, displaying detailed information about the images, comparison process, and computed metrics to standard error.
-quiet
Suppresses all warning or error messages, useful for scripting where only the return code or metric value is needed.
DESCRIPTION
The magick-compare command, a utility from the ImageMagick suite, is used to compare two images visually and algorithmically. It's an indispensable tool for visual regression testing, quality assurance, and detecting subtle changes between image versions.
By default, it generates a new image highlighting the discrepancies between the input_image and the reference_image, often with differing pixels colored distinctly. Beyond visual comparison, it can also calculate various image metrics, such as Mean Absolute Error (MAE), Root Mean Square Error (RMSE), and Peak Signal-to-Noise Ratio (PSNR), providing a quantifiable measure of image similarity or difference. This allows users to not only see where images differ but also to get a numerical score of their dissimilarity.
CAVEATS
For accurate comparisons, both input images should ideally have the same dimensions, format, and color profiles. Differences in these attributes might lead to misleading results or errors, or prevent a direct pixel-by-pixel comparison. Calculating some metrics, especially for very large images, can be resource-intensive. The interpretation of difference images and numerical metrics can sometimes be subjective; a small numerical difference might be visually significant, or vice-versa, depending on the context.
METRIC INTERPRETATION
Understanding magick-compare's output often involves interpreting the metrics. For instance, a MAE (Mean Absolute Error) or RMSE (Root Mean Square Error) of 0 indicates identical images, while higher values mean greater dissimilarity. PSNR (Peak Signal-to-Noise Ratio) is inversely related: higher PSNR usually means more similar images, while lower values indicate more noise or distortion. Different metrics are suited for different types of comparisons.
COMMON USE CASES
Visual Regression Testing: Automating checks in software development to ensure UI changes or image processing modifications do not unintentionally alter visual elements.
Quality Assurance: Verifying that generated images meet specific quality standards or match a 'golden reference' image.
Forensics & Integrity: Detecting alterations or tampering in images, or checking if an image file has been modified or corrupted since its last known state.
HISTORY
The magick-compare utility is an integral part of the ImageMagick software suite, which was first released in 1987. ImageMagick was originally developed by John Cristy at DuPont and has evolved significantly over decades to become a comprehensive open-source image processing toolkit. The compare functionality has been a core component for a long time, evolving alongside ImageMagick's capabilities, becoming a standard for automated visual testing and quality control in various development pipelines and artistic workflows.