Skip to content

Instantly share code, notes, and snippets.

@homm
Last active December 15, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save homm/5228221 to your computer and use it in GitHub Desktop.
Save homm/5228221 to your computer and use it in GitHub Desktop.
from PIL import Image
from timeit import repeat
from image import paste_composite
im1 = Image.open('in1.png')
im1.load()
im2 = Image.open('in2.png')
im2.load()
print repeat(lambda: paste_composite(im1.copy(), im2), number=100)
print repeat(lambda: Image.alpha_composite(im1, im2), number=100)
out1 = im1.copy()
paste_composite(out1, im2)
out1.save('out1.png')
out2 = Image.alpha_composite(im1, im2)
out2.save('out2.png')
from PIL import Image, ImageMath
def chanel_diff(c1, c2):
c = ImageMath.eval('127 + c1 - c2', c1=c1, c2=c2).convert('L')
return c.point(lambda c: c if 126 <= c <= 128 else 127 + (c - 127) * 10)
im1 = Image.open('out2.png')
im2 = Image.open('ref.png')
diff = map(chanel_diff, zip(im1.split(), im2.split()))
Image.merge('RGB', diff[:-1]).save('diff.png', optimie=True)
diff[-1].convert('RGB').save('diff.alpha.png', optimie=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment