from PIL import Image
from PIL import ImageChops
from PIL import ImageEnhance
+from PIL import ImageFilter
thumb_size = 320, 320
+gaussian_kernel = ImageFilter.Kernel((3, 3), [1, 2, 1, 2, 4, 2, 1, 2, 1], 16)
class Comparer:
'''Image comparer.'''
diff_im = Image.blend(self.src_im, diff_im, 0xcc/255.0)
diff_im.save(diff_image)
- def precision(self):
+ 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 = self.diff.histogram()
+ h = diff.histogram()
square_error = 0
for i in range(1, 256):
square_error += sum(h[i : 3*256: 256])*i*i
def is_image(path):
- return \
- path.endswith('.png') \
- and not path.endswith('.diff.png') \
- and not path.endswith('.thumb.png')
+ name = os.path.basename(path)
+ name, ext1 = os.path.splitext(name)
+ name, ext2 = os.path.splitext(name)
+ return ext1 in ('.png', '.bmp') and ext2 not in ('.diff', '.thumb')
def find_images(prefix):
- prefix = os.path.abspath(prefix)
if os.path.isdir(prefix):
prefix_dir = prefix
else:
html.write('<html>\n')
html.write(' <body>\n')
html.write(' <table border="1">\n')
- html.write(' <tr><th>%s</th><th>%s</th><th>Δ</th></tr>\n' % (ref_prefix, src_prefix))
+ html.write(' <tr><th>File</th><th>%s</th><th>%s</th><th>Δ</th></tr>\n' % (ref_prefix, src_prefix))
for image in images:
ref_image = ref_prefix + image
src_image = src_prefix + image
comparer.write_diff(delta_image, fuzz=options.fuzz)
html.write(' <tr>\n')
+ html.write(' <td>%s</td>\n' % (image,))
surface(html, ref_image)
surface(html, src_image)
surface(html, delta_image)