diffimg
Visually compare two images for differences
TLDR
Calculate the intersection between images and output an image where each pixel is the difference between corresponding pixels in input images
SYNOPSIS
diffimg [OPTIONS] <IMAGE1_PATH> <IMAGE2_PATH>
PARAMETERS
<IMAGE1_PATH>
The path to the first image file for comparison.
<IMAGE2_PATH>
The path to the second image file for comparison.
--threshold <value>
Sets the sensitivity for pixel difference. Pixels differing by less than this value are considered identical. The range and meaning of <value> can vary (e.g., 0-255 for RGB channels, or a percentage).
--output <file>
Specifies the path where the generated difference image should be saved. This image typically highlights the pixels that differ between the input images.
--diff-color <color>
Defines the color used to highlight differences in the output image (e.g., `red`, `#FF0000`).
--exit-code-on-diff
Returns a non-zero exit code if differences are detected between the two images, useful for scripting and automation.
--metric <type>
Specifies the metric used for comparison (e.g., `RMSE` for Root Mean Squared Error, `PSNR` for Peak Signal-to-Noise Ratio). Not all implementations support this.
--verbose
Enables verbose output, providing more details about the comparison process and results to standard output.
--help
Displays a help message with available options and usage.
--version
Shows the command's version information.
DESCRIPTION
diffimg is a utility designed to visually compare two image files and identify areas where they differ. Unlike a byte-level comparison tool like diff, diffimg understands image formats and performs a pixel-by-pixel analysis. When differences are found, it typically generates a third output image that highlights these discrepancies, often by overlaying a distinct color on the changed pixels, or by showing only the differing regions. This command is invaluable for tasks such as automated visual regression testing in software development, verifying image transformations, or ensuring consistency across different versions of graphical assets. Its ability to produce a visual representation of changes makes it highly effective for quickly pinpointing even subtle alterations that might be missed by the human eye alone.
CAVEATS
The diffimg command is not a standard, universally pre-installed Linux utility like ls or grep. Its availability, exact options, and behavior can vary significantly depending on the specific implementation you are using. It might be a custom script, part of a larger image processing suite (though compare from ImageMagick is more common for this purpose), or a standalone program compiled from source. Users should consult the documentation for their specific diffimg version or verify its presence and usage on their system.
TYPICAL USE CASES
Visual Regression Testing: Automatically verifying that changes to code (e.g., CSS, UI framework updates) do not inadvertently introduce visual discrepancies in web pages or application interfaces.
Asset Verification: Ensuring that different versions of images or icons are identical or that image processing steps produce the expected visual output.
Quality Assurance: Aiding in manual or automated QA processes by providing clear visual feedback on unintended graphical changes.
HISTORY
The concept of diffimg emerged from the growing need to compare graphical assets beyond simple byte-level differences. While traditional diff commands are excellent for text and generic binary files, they are unsuitable for image comparisons where a single pixel shift or color change can alter a file without changing its byte size or structure in a way diff can interpret meaningfully. Specific diffimg implementations have typically been developed as standalone tools or custom scripts to address visual regression testing and quality assurance challenges in various domains, such as web development, game development, and graphic design, where visual fidelity is paramount.