You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Get the % difference in images using PIL's histogram + generate a diff image. Images
should have the same color channels (for example, RGB vs RGBA). If the image dimensions
differ, the 2nd image will be resized to match the first before calculating the diff.
Installation
Now available from PyPi: pip install diffimg
Usage
>>> from diffimg import diff
>>> diff('mario-circle-cs.png', 'mario-circle-node.png')
0.007319618135968298
The very simplediff function returns a raw ratio instead of a
% by default.
delete_diff_file: a file showing the differing areas of the two images is generated in
order to measure the diff ratio with the same dimensions as the first image. Setting
this to True removes it after calculating the ratio.
diff_img_file: filename for the diff image file. Defaults to diff_img.png
(regardless of inputed file's types).
ignore_alpha: ignore the alpha channel for the ratio and if applicable, sets the alpha
of the diff image to fully opaque.
--ratio outputs a number between 0 and 1 instead of the default Images differ by X%.
--delete removes the diff file after retrieving ratio/percentage.
--filename specifies a filename to save the diff image under. Must use a valid extension.
--ignore-alpha ignore the alpha channel.
Tests
$ ./test.py
......
----------------------------------------------------------------------
Ran 6 tests in 0.320s
OK
Formula
The difference is defined by the average % difference between each of the channels
(R,G,B,A?) at each pair of pixels Axy, Bxy at the same coordinates
in each of the two images (why they need to be the same size), averaged over all pairs
of pixels.
For example, compare two 1x1 images A and B (a trivial example, >1 pixels would have
another step to find the average of all pixels):