Ben Chuanlong Du's Blog

It is never too late to learn.

Hands-on the ImageChops class in Pillow in Python

In [6]:
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.

In [9]:
img_4h = Image.open("../../home/media/poker/4h.png")
img_4h
Out[9]:
In [12]:
img_4_dither = img_4h.convert("1")
img_4_dither
Out[12]:
In [13]:
img_4 = img_4h.convert("1", dither=False)
img_4
Out[13]:
In [14]:
ImageChops.difference(img_4_dither, img_4)
Out[14]:
In [ ]:
 

Comments