color.py
Go to the documentation of this file.
1 import numpy as np
2 
3 
4 # Taken from https://github.com/wkentaro/imgviz/blob/master/imgviz/label.py # NOQA
5 def labelcolormap(N=256):
6  """Label colormap.
7  Parameters
8  ----------
9  N: int
10  Number of labels (default: 256).
11 
12  Returns
13  -------
14  cmap: numpy.ndarray, (N, 3), numpy.uint8
15  Label id to colormap.
16  """
17 
18  def bitget(byteval, idx):
19  shape = byteval.shape + (8,)
20  return np.unpackbits(byteval).reshape(shape)[..., -1 - idx]
21 
22  i = np.arange(N, dtype=np.uint8)
23  r = np.full_like(i, 0)
24  g = np.full_like(i, 0)
25  b = np.full_like(i, 0)
26 
27  i = np.repeat(i[:, None], 8, axis=1)
28  i = np.right_shift(i, np.arange(0, 24, 3)).astype(np.uint8)
29  j = np.arange(8)[::-1]
30  r = np.bitwise_or.reduce(np.left_shift(bitget(i, 0), j), axis=1)
31  g = np.bitwise_or.reduce(np.left_shift(bitget(i, 1), j), axis=1)
32  b = np.bitwise_or.reduce(np.left_shift(bitget(i, 2), j), axis=1)
33 
34  cmap = np.stack((r, g, b), axis=1).astype(np.uint8)
35  return cmap
jsk_recognition_utils.color.labelcolormap
def labelcolormap(N=256)
Definition: color.py:5


jsk_recognition_utils
Author(s):
autogenerated on Sat Feb 22 2025 04:03:28