Advertisement
furas

Pillow - substract images to find differences

Jul 30th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. from PIL import Image, ImageChops
  2. import numpy as np
  3.  
  4. FOLDER = '/home/username/'
  5. img1 = Image.open(FOLDER + 'image1.png').convert('RGB') # without A (RGBA) to remove transparency
  6. img2 = Image.open(FOLDER + 'image2.png').convert('RGB') # without A (RGBA) to remove transparency
  7.  
  8. diff = ImageChops.difference(img2, img1).convert('L') # L = grayscale (it will covert three numbers R,G,B into one number)
  9. diff.save(FOLDER + 'diff.png')
  10.  
  11. arr = np.asarray(diff) # convert to numpy's array
  12. data = np.nonzero(arr) # find nonzero values
  13.  
  14. for x, y  in zip(data[0], data[1]):
  15.     print(x, y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement