-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathg_color.py
26 lines (22 loc) · 976 Bytes
/
g_color.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
import os
from PIL import Image
import glob
import numpy as np
from utils import make_folder
color_list = [[0, 0, 0], [204, 0, 0], [76, 153, 0], [204, 204, 0], [51, 51, 255], [204, 0, 204], [0, 255, 255], [255, 204, 204], [102, 51, 0], [255, 0, 0], [102, 204, 0], [255, 255, 0], [0, 0, 153], [0, 0, 204], [255, 51, 153], [0, 204, 204], [0, 51, 0], [255, 153, 51], [0, 204, 0]]
folder_base = 'predictionimages'
folder_save = 'predictionimages-color'
img_num = 12
make_folder(folder_save)
for k in range(img_num):
filename = os.path.join(folder_base, str(k) + '.png')
if (os.path.exists(filename)):
im_base = np.zeros((512, 512, 3))
im = Image.open(filename)
im = np.array(im)
for idx, color in enumerate(color_list):
im_base[im == idx] = color
filename_save = os.path.join(folder_save, str(k) + '.png')
result = Image.fromarray((im_base).astype(np.uint8))
print (filename_save)
result.save(filename_save)