Created
August 31, 2016 17:49
-
-
Save Flushot/64cdb9351d1474c91c0e449e6bc0f37b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import ImageChops, ImageDraw | |
def create_diff_image(img1, img2): | |
""" | |
Compares two Images and either creates an Image with differences | |
outlined with red bounding boxes, or returns None if no differences | |
were found. | |
""" | |
diff_img = img2.copy() | |
differences = ImageChops.differences(img1, img2) | |
bounding_box = differences.getbbox() | |
if bounding_box is None: | |
diff_img.close() | |
return None | |
else: | |
draw = ImageDraw.Draw(diff_img) | |
draw.rect(bounding_box, outline=(255, 0, 0)) | |
return diff_img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment