Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Hands-on the ImageChops class in Pillow in Python

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import numpy as np
from PIL import Image, ImageOps, ImageChops

ImageChops.difference

ImageChops.difference calcualte the difference image of 2 images. Notice that the type/dimension of the 2 images must match.

img_4h = Image.open("../../home/media/poker/4h.png")
img_4h
<PIL.PngImagePlugin.PngImageFile image mode=RGB size=37x54 at 0x7F63C7075F60>
img_4_dither = img_4h.convert("1")
img_4_dither
<PIL.Image.Image image mode=1 size=37x54 at 0x7F63C7013358>
img_4 = img_4h.convert("1", dither=False)
img_4
<PIL.Image.Image image mode=1 size=37x54 at 0x7F63C7013828>
ImageChops.difference(img_4_dither, img_4)
<PIL.Image.Image image mode=1 size=37x54 at 0x7F63C7013978>