#!/usr/bin/env python3 """How far one picture sits from another: the rule behind every "Moved" figure on the page. python3 distance.py control.png test.png Needs Pillow. It reads two pictures of the same size and prints one number: the mean absolute difference between them, over every pixel and the three colour channels, on a scale of 0 to 255. Zero is the same pixels. On the page, a subject's figure is the mean of this number over its two counted seeds (202 and 303), each test picture against the control picture at the same subject and seed, and a table prints the least and the most moved of the six subjects. The page read it on lossless PNG masters, which this kit does not carry; on the JPEG pictures the page shows, the number will differ a little, because JPEG changes pixels of its own. It is a distance and not a score: it cannot say which picture is the one to keep. """ import sys from PIL import Image, ImageChops, ImageStat def distance(path_a, path_b): with Image.open(path_a) as a, Image.open(path_b) as b: a, b = a.convert("RGB"), b.convert("RGB") if a.size != b.size: sys.exit("the two pictures are not the same size: %s and %s" % (a.size, b.size)) return sum(ImageStat.Stat(ImageChops.difference(a, b)).mean) / 3.0 if __name__ == "__main__": if len(sys.argv) != 3: sys.exit(__doc__) print("%.3f" % distance(sys.argv[1], sys.argv[2]))