3000 explained code solutions for 75 technologies


python-pillowHow to find difference between images


from PIL import Image, ImageChops

im1 = Image.open('/var/www/examples/heroine.png').convert('RGBA')
im2 = Image.open('/var/www/examples/hero.png').convert('RGBA')
diff = ImageChops.difference(im1, im2)ctrl + c
PIL

import Pillow package modules

Image.open

open given image with Pillow

ImageChops.difference(

calculates pixel-by-pixel difference between given images and returns it


Usage example

from PIL import Image, ImageChops

im1 = Image.open('/var/www/examples/heroine.png').convert('RGBA')
im2 = Image.open('/var/www/examples/hero.png').convert('RGBA')
diff = ImageChops.difference(im1, im2)

print(len(diff.getdata()))
output
806300