- # See also http://effbot.org/zone/pil-comparing-images.htm
- # TODO: this is approximate due to the grayscale conversion
- h = diff.convert('L').histogram()
- ae = sum(h[255 * options.fuzz // 100 + 1 : 256])
- return ae
+ def precision(self):
+ # See also http://effbot.org/zone/pil-comparing-images.htm
+ h = self.diff.histogram()
+ square_error = 0
+ for i in range(1, 256):
+ square_error += sum(h[i : 3*256: 256])*i*i
+ rel_error = float(square_error*2 + 1) / float(self.diff.size[0]*self.diff.size[1]*3*255*255*2)
+ bits = -math.log(rel_error)/math.log(2.0)
+ return bits
+
+ def ae(self):
+ # Compute absolute error
+ # TODO: this is approximate due to the grayscale conversion
+ h = self.diff.convert('L').histogram()
+ ae = sum(h[int(255 * fuzz) + 1 : 256])
+ return ae