-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADPCX.py
29 lines (27 loc) · 1016 Bytes
/
ADPCX.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import PIL
from PIL import Image
from PIL import ImageFilter
from PIL import ImageChops
from PIL import ImageOps
def do_it (photo1,photo2,output,alphapath,cutoff=100,ax=0,ay=0,bx=0,by=0): # cutoff 0 -- 255
ph1 = Image.open(photo1)
ph2 = Image.open(photo2)
## make sure they're the same size
aw,ah = ph1.size
bw,bh = ph2.size
w = min(aw,bw)
h = min(ah,bh)
ph1 = ph1.crop((ax,ay,w + ax,h + ay))
ph2 = ph2.crop((bx,by,w + bx,h + by))
if ph1.mode != ph2.mode:
ph2 = ph2.convert(ph1.mode)
blur1 = ph1.filter(ImageFilter.BLUR)
blur2 = ph2.filter(ImageFilter.BLUR)
alphachannel0 = ImageChops.difference(blur1,blur2)
alphachannel1 = ImageOps.grayscale(alphachannel0)
alphachannel2 = Image.eval(alphachannel1,lambda px:0 if px < cutoff else 255)
alphachannel3 = alphachannel2.filter(ImageFilter.BLUR)
alphachannel3.convert('1')
alphachannel3.save(alphapath,format='png')
ph1.paste(ph2,None,alphachannel3)
ph1.save(output,format='png')