-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset_colormap.py
39 lines (29 loc) · 1.05 KB
/
dataset_colormap.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
import numpy as np
def create_label_colormap():
"""Creates a label colormap used in EGO_HAND_SEG dataset.
Returns:
A colormap for visualizing segmentation results.
"""
return np.asarray([
[0, 0, 0], # black
[255, 6, 51] # torch red
# [255, 255, 255] # white
])
def label_to_color_image(label):
"""Adds color defined by the colormap to the label.
Args:
label: A 2D array with integer type, storing the segmentation label.
Returns:
result: A 2D array with floating type. The element of the array
is the color indexed by the corresponding element in the input label
to the color map.
Raises:
ValueError: If label is not of rank 2 or its value is larger than color
map maximum entry.
"""
if label.ndim != 2:
raise ValueError('Expect 2-D input label')
colormap = create_label_colormap()
if np.max(label) >= len(colormap):
raise ValueError('label value too large.')
return colormap[label]