LinuxCommandLibrary

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

$ diffimg [path/to/input_image1.ext] [path/to/input_image2.ext] [path/to/output_image.ext]
copy

SYNOPSIS

diffimg [options] image1 image2 [output_image]

PARAMETERS

-h, --help
    Show the help message and exit.

-v, --version
    Show program's version number and exit.

-d THRESHOLD, --diff-ratio=THRESHOLD
    Sets the threshold (0.0-1.0) to define when a pixel is different. Default: 0.01

-f, --fail-fast
    Exit immediately with an error code if differences are detected. This is mostly suitable for automation.

-e, --equal
    Treat images as equal even if they differ. The exit code is still zero if differences are seen. Useful to automatically generate difference images for a set of samples.

-c COLOR, --highlight-color=COLOR
    Specify the color to highlight differences. COLOR must be a hexadecimal color code (e.g., #FF0000 for red).

-m METRIC, --metric=METRIC
    Specify the metric to use for the comparison. Default: MSE. Valid metrics are MSE, RMSE, PSNR, SSIM.

image1
    The first image to compare.

image2
    The second image to compare.

[output_image]
    Optional. The name of the output image where the differences will be visualized. If not provided, the difference image is not saved to file.

DESCRIPTION

The `diffimg` command is a command-line tool used to visually compare two images. It analyzes the images and generates a difference image highlighting areas where the images differ. It is particularly useful for identifying subtle changes between image versions, detecting artifacts introduced during image processing, or verifying the correctness of image transformations. `diffimg` supports various image formats and provides options to control the comparison process, such as setting a threshold for difference detection and creating different kinds of images which expose the exact changes.

The primary output is a comparison image which usually displays the differences in a way that is easy for a human to visually identify. It is also possible to output numeric difference metrics between the images to quantify the exact changes. This approach can be useful when there is a need to create an automated workflow to identify changes between images.

CAVEATS

The effectiveness of `diffimg` depends on the similarity of the images and the chosen threshold. Large differences or significant image distortions may result in inaccurate or difficult-to-interpret results. It is also important to note that even perfectly identical images may have minor differences because of different compression methods.

EXIT STATUS

The exit status is 0 if no differences are found (or if `-e` flag is set), and non-zero otherwise (when `-f` is set, the exit code is non-zero immediately when a difference is detected).

IMAGE FORMATS

diffimg generally supports a wide range of image formats depending on the underlying image processing libraries installed. Common formats include PNG, JPG, GIF, BMP, and TIFF.

SEE ALSO

compare(1), imagemagick(1)

Copied to clipboard