Pillow - substract images to find differences
furas Jul 30th, 2018 (edited) 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- from PIL import Image, ImageChops
- import numpy as np
- FOLDER = '/home/username/'
- img1 = Image.open(FOLDER + 'image1.png').convert('RGB') # without A (RGBA) to remove transparency
- img2 = Image.open(FOLDER + 'image2.png').convert('RGB') # without A (RGBA) to remove transparency
- diff = ImageChops.difference(img2, img1).convert('L') # L = grayscale (it will covert three numbers R,G,B into one number)
- diff.save(FOLDER + 'diff.png')
- arr = np.asarray(diff) # convert to numpy's array
- data = np.nonzero(arr) # find nonzero values
- for x, y in zip(data, data):
- print(x, y)
RAW Paste Data