I'm looking through the Python Imaging Library docs for a way to take 2 similar images and "subtract one from the other". Here is a visual aid:
We've all seen these nifty "turning a word into its meaning" things, right? I want to basically take the second image and subtract the first image, so I want to return only the lines added to the word "cat" to make the actual cat. What functions will help me along with doing this?
Update: I've been working on this continuously while waiting. This is what I've tried.
import numpy as np
from PIL import Image
from PIL import ImageChops
import math,operator, matplotlib.cm as cm
img1 = Image.open("cat1.PNG")
img2 = Image.open("cat2.PNG")
img1array = (list(img1.getdata()))
img1new = Image.fromarray(np.uint8(cm.gist_earth(img1array)*255))
img2array = (list(img2.getdata()))
img2new = Image.fromarray(np.uint8(cm.gist_earth(img2array)*255))
dif = np.fabs(np.subtract(img2array[:], img1array[:]))
difimg = Image.fromarray(np.uint8(cm.gist_earth(dif)*255))
difimg.save("out1.PNG")
However, this outputs a file that Windows 10 can't even open. My idea was to convert both images to an array, subtract them, and then recreate the difference as an image. This does indeed save a file called out1.PNG
, but Windows gives an error when trying to open it: We can't open this file.
Note - I resized the 2nd image using an online resizer, PIL was giving me problems about size differences...