Finding Differences in Images with Python and Pillow

Finding Differences in Images with Python and Pillow

May 20, 2025

Mike’s article about using Pillow to find differences in images.

In his example, you could output the difference using a simple function:

from PIL import Image, ImageChops

def diff(image_path_one, image_path_two, output_path):
    image_one = Image.open(image_path_one)
    image_two = Image.open(image_path_two)
    image_three = ImageChops.difference(image_one, image_two)
    image_three.save(output_path)

if __name__ = "__main__":
    diff("yellow_butterfly.jpg","watermarked_butterfly.jpg")

I can see how this could be useful to do a compare of a given picture like what Mike did or take a image of a chart and compare the differences as well.