-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel_mixer.py
48 lines (41 loc) · 1.37 KB
/
channel_mixer.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from PIL import Image
def get_channel_mix(path_r, path_g, path_b, path_a, size):
imr = None
if path_r != '':
imr = Image.open(path_r).convert('L')
imr = imr.resize((size, size))
else:
imr = Image.new('L', (size, size), color=255)
img = None
if path_g != '':
img = Image.open(path_g).convert('L')
img = img.resize((size, size))
else:
img = Image.new('L', (size, size), color=255)
imb = None
if path_b != '':
imb = Image.open(path_b).convert('L')
imb = imb.resize((size, size))
else:
imb = Image.new('L', (size, size), color=255)
ima = None
if path_a != '':
ima = Image.open(path_a).convert('L')
ima = ima.resize((size, size))
else:
ima = Image.new('L', (size, size), color=255)
"""
imr = Image.open(path_r).convert('L')
imr = imr.resize((size, size))
img = Image.open(path_g).convert('L')
img = img.resize((size, size))
imb = Image.open(path_b).convert('L')
imb = imb.resize((size, size))
ima = Image.open(path_a).convert('L')
ima = ima.resize((size, size))
"""
return Image.merge('RGBA', (imr, img, imb, ima))
def get_channel_split(path, size):
im = Image.open(path)
im = im.resize((size, size))
return im.getchannel('R'), im.getchannel('G'), im.getchannel('B'), im.getchannel('A')