-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_mask.py
More file actions
28 lines (26 loc) · 998 Bytes
/
Copy pathmerge_mask.py
File metadata and controls
28 lines (26 loc) · 998 Bytes
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
import os
import cv2
from PIL import Image
import numpy as np
from tqdm import tqdm
import argparse
import json
parser = argparse.ArgumentParser(description="Parameter for merging masks.")
parser.add_argument('--path', type=str, default='example_mix.json')
args = parser.parse_args()
with open(args.path, 'r') as f:
folder_pth = json.load(f)
for i in tqdm(folder_pth):
for k in range(12):
mask_pth = os.path.join(i, f"mask_{k:03d}")
if not os.path.exists(os.path.join(mask_pth, 'mixed_mask.png')):
img_lst = os.listdir(mask_pth)
img_lst.sort()
cur_num = 2
empty = np.ones((512, 512))
for img in img_lst:
if (int(img.split('_')[-3]) == 0):
tmp_img = cv2.imread(os.path.join(mask_pth, img), cv2.IMREAD_GRAYSCALE)
empty[np.where(tmp_img != 0)] = cur_num
cur_num += 1
cv2.imwrite(os.path.join(mask_pth, 'mixed_mask.png'), empty)