Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image, ImageEnhance
- import numpy
- import blend_modes
- import sys
- import scipy
- background_img_raw = Image.open(sys.argv[1])
- background_img_raw.putalpha(255)
- background_img = numpy.array(background_img_raw)
- background_img_float = background_img.astype(float)
- foreground_img_raw = Image.open(sys.argv[2])
- foreground_img_raw.putalpha(255)
- foreground_img = numpy.array(foreground_img_raw)
- foreground_img_float = foreground_img.astype(float)
- opacity = 1.0
- blended_img_float = blend_modes.difference(background_img_float, foreground_img_float, opacity)
- r, g, b, a = np.transpose(blended_img_float)
- alpha = np.clip((r+g+b)*2, 0, 255)
- r = np.clip(r + 100, 0, 255)
- g = np.clip(g + 100, 0, 255)
- b = np.clip(b + 100, 0, 255)
- blended_img_float = np.transpose([r, g, b, alpha])
- blended_img = numpy.uint8(blended_img_float)
- blended_img_raw = Image.fromarray(blended_img)
- blended_img_raw.save(sys.argv[3])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement