PIL: Getting a two color difference between images

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sat Oct 25 19:41:51 CEST 2008


Kevin D. Smith:
> What I want is a two color output image: black where the image wasn't different, and white where it was different.<

There are several ways to do that. If speed isn't essential, then you
can create a third blank image of the right size, and then use the
method that iterates on the pixels of an image, and assign p1 != p2 at
every pixel of the third image.

If speed is important you can copy the images into numpy arrays and
then your operation becomes easy.

Maybe there are built-in ways in PIL too, I don't know. You can also
find an intermediate solution, like computing the difference image
with PIL and then binarize it manually.

Bye,
bearophile



More information about the Python-list mailing list