-
Notifications
You must be signed in to change notification settings - Fork 34
/
convert_labels.py
53 lines (42 loc) · 1.13 KB
/
convert_labels.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
50
51
52
53
import os
import cv2
from tqdm import tqdm
import argparse
parse = argparse.ArgumentParser()
parse.add_argument('--img-path', type=str, default='')
parse.add_argument('--save-path', type=str, default='')
parse.add_argument('--mode', type=str, default='segmentation')
args = parse.parse_args()
data_path = args.img_path
save_path = args.save_path
limgs = os.listdir(data_path)
pd = tqdm(total=17706)
if args.mode == 'segmentation':
for item in limgs:
pd.update(1)
im = cv2.imread(data_path + item)
im[im != 0] = 1
cv2.imwrite(save_path + item, im)
else:
for item in limgs:
pd.update(1)
im = cv2.imread(data_path + item)
im[im == 1] = 1
im[im == 2] = 1
im[im == 3] = 1
im[im == 17] = 1
im[im == 11] = 1
im[im == 4] = 2
im[im == 14] = 3
im[im == 15] = 3
im[im == 5] = 4
im[im == 6] = 4
im[im == 7] = 4
im[im == 8] = 4
im[im == 9] = 4
im[im == 10] = 4
im[im == 12] = 4
im[im == 13] = 4
im[im == 16] = 0
cv2.imwrite(save_path + item, im)
pd.close()