-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvisualizeDataset.py
More file actions
47 lines (34 loc) · 1.55 KB
/
Copy pathvisualizeDataset.py
File metadata and controls
47 lines (34 loc) · 1.55 KB
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
import glob
import numpy as np
import cv2
import random
import argparse
def imageSegmentationGenerator(images_path, segs_path, n_classes):
assert images_path[-1] == '/'
assert segs_path[-1] == '/'
images = glob.glob(images_path + "*.jpg") + glob.glob(images_path + "*.png") + glob.glob(images_path + "*.jpeg")
images.sort()
segmentations = glob.glob(segs_path + "*.jpg") + glob.glob(segs_path + "*.png") + glob.glob(segs_path + "*.jpeg")
segmentations.sort()
colors = [(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) for _ in range(n_classes)]
assert len(images) == len(segmentations)
for im_fn, seg_fn in zip(images, segmentations):
assert (im_fn.split('/')[-1] == seg_fn.split('/')[-1])
img = cv2.imread(im_fn)
seg = cv2.imread(seg_fn)
print(np.unique(seg))
seg_img = np.zeros_like(seg)
for c in range(n_classes):
seg_img[:, :, 0] += ((seg[:, :, 0] == c) * (colors[c][0])).astype('uint8')
seg_img[:, :, 1] += ((seg[:, :, 0] == c) * (colors[c][1])).astype('uint8')
seg_img[:, :, 2] += ((seg[:, :, 0] == c) * (colors[c][2])).astype('uint8')
cv2.imshow("img", img)
cv2.imshow("seg_img", seg_img)
if cv2.waitKey() == 27:
return
parser = argparse.ArgumentParser()
parser.add_argument("--images", type=str)
parser.add_argument("--annotations", type=str)
parser.add_argument("--n_classes", type=int)
args = parser.parse_args()
imageSegmentationGenerator(args.images, args.annotations, args.n_classes)