PIL: Getting a two color difference between images
Kevin D. Smith
Kevin.Smith at sas.com
Mon Oct 27 11:02:05 EDT 2008
On 2008-10-25 12:41:51 -0500, bearophileHUGS at lycos.com said:
> 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.
This last method is what I ended up doing for now. I use the PIL
differencing function, then walk through the result of getdata() to
binarize it. I was hoping there might be a way to run a filter or
something that might be faster, but I haven't figured it out.
--
Kevin D. Smith
More information about the Python-list
mailing list