- # 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[int(255 * options.fuzz) + 1 : 256])
- return ae
+ diff_im = Image.blend(self.src_im, diff_im, 0xcc/255.0)
+ diff_im.save(diff_image)
+
+ def precision(self, filter=False):
+ if self.size_mismatch():
+ return 0.0
+
+ diff = self.diff
+ if filter:
+ diff = diff.filter(gaussian_kernel)
+
+ # See also http://effbot.org/zone/pil-comparing-images.htm
+ h = 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, fuzz = 0.05):
+ # Compute absolute error
+
+ if self.size_mismatch():
+ return sys.maxint
+
+ # 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