-
Notifications
You must be signed in to change notification settings - Fork 0
/
palette.py
49 lines (46 loc) · 1.25 KB
/
palette.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
49
from PIL import Image
import numpy as np
# palette = [0, 200, 0,
# 150, 250, 0,
# 150, 200, 150,
# 200, 0, 200,
# 150, 0, 250,
# 150, 150, 250,
# 250, 200, 0,
# 200, 200, 0,
# 200, 0, 0,
# 250, 0, 150,
# 200, 150, 150,
# 250, 150, 150,
# 0, 0, 200,
# 0, 150, 200,
# 0, 200, 250,
# 0, 0, 0]
palette = [0, 200, 0,
150, 250, 0,
150, 200, 150,
200, 0, 200,
150, 0, 250,
150, 150, 250,
250, 200, 0,
200, 200, 0,
200, 0, 0,
250, 0, 150,
200, 150, 150,
250, 150, 150,
0, 0, 200,
0, 150, 200,
0, 200, 250,
0, 0, 0]
#print(len(palette)) #48
zero_pad = 256 * 3 - len(palette)
#print(zero_pad) #720
for i in range(zero_pad):
palette.append(0)
# 将grey mask转化为彩色mask
#print(len(palette)) #768
#palette 是一个包含256个RGB值的列表
def colorize_mask(mask):
mask_color = Image.fromarray(mask.astype(np.uint8)).convert('P')
mask_color.putpalette(palette)
return mask_color