1.首先我们需要生成一个color list,例如下面所示,表示2个颜色
[[255,0,0],
[0,255,0]]
生成的代码如下,从google的deeplabv3+代码里面找出来的
def bit_get(val, idx):
"""Gets the bit value.
Args:
val: Input value, int or numpy int array.
idx: Which bit of the input val.
Returns:
The "idx"-th bit of input val.
"""
return (val >> idx) & 1
def create_pascal_label_colormap(class_num):
"""Creates a label colormap used in PASCAL VOC segmentation benchmark.
Returns:
A colormap for visualizing segmentation results.
"""
colormap = np.zeros((class_num, 3), dtype=int)
ind = np.arange(class_num, dtype=int)
for shift in reversed(range(8)):
for channel in range(3):
colormap[:, channel] |= bit_get(ind, channel) << shift
ind >>= 3
return colormap
生成colo