File size: 560 Bytes
72dddd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from PIL import Image

image = Image.open('mask2.png')

def toBlackWhiteMask(input_pil):
    if input_pil.mode != 'RGBA':
        input_pil = input_pil.convert('RGBA')

    new_image = Image.new('RGBA', input_pil.size, (255, 255, 255, 255))

    input_data = input_pil.getdata()
    new_data = []

    for item in input_data:
        if item[3] == 0:
            new_data.append((0, 0, 0, 255))
        else:
            new_data.append((255, 255, 255, 255))

    new_image.putdata(new_data)

    return new_image

transform_image(image).save('mask2_nice.png')