Archive for the ‘imaging’ category

2 Bilder mit Python vergleichen

December 28th, 2009

Hier ein kleines Tutorial wie man zwei Bilder mit Python bzw. mit PIL (Python Imaging Library) vergleicht. Sofern die zwei Bilder gleich sind geben wir ‘True‘ zurück, andernfalls ein None.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import ImageChops
import Image
 
def img_equal(im1, im2):
    im1 = Image.open(im1)
    im2 = Image.open(im2)
    return ImageChops.difference(im1, im2).getbbox() is None
 
if img_equal('/home/someshot.png', '/home/anotherone.png'):
    print 'jepp - they are equal'
else:
    print 'everything ok - keep on rockin'