Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. from PIL import Image, ImageEnhance
  2. import numpy
  3. import blend_modes
  4. import sys
  5. import scipy
  6.  
  7.  
  8. background_img_raw = Image.open(sys.argv[1])
  9. background_img_raw.putalpha(255)
  10. background_img = numpy.array(background_img_raw)
  11. background_img_float = background_img.astype(float)
  12. foreground_img_raw = Image.open(sys.argv[2])
  13. foreground_img_raw.putalpha(255)
  14. foreground_img = numpy.array(foreground_img_raw)
  15. foreground_img_float = foreground_img.astype(float)
  16. opacity = 1.0
  17. blended_img_float = blend_modes.difference(background_img_float, foreground_img_float, opacity)
  18. r, g, b, a = np.transpose(blended_img_float)
  19. alpha = np.clip((r+g+b)*2, 0, 255)
  20. r = np.clip(r + 100, 0, 255)
  21. g = np.clip(g + 100, 0, 255)
  22. b = np.clip(b + 100, 0, 255)
  23. blended_img_float = np.transpose([r, g, b, alpha])
  24. blended_img = numpy.uint8(blended_img_float)
  25. blended_img_raw = Image.fromarray(blended_img)
  26. blended_img_raw.save(sys.argv[3])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement