MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / get_different_colors

Function get_different_colors

detrsmpl/utils/demo_utils.py:682–715  ·  view source on GitHub ↗

Get a numpy of colors of shape (N, 3).

(number_of_colors,
                         flag=0,
                         alpha: float = 1.0,
                         mode: str = 'bgr',
                         int_dtype: bool = True)

Source from the content-addressed store, hash-verified

680
681
682def get_different_colors(number_of_colors,
683 flag=0,
684 alpha: float = 1.0,
685 mode: str = 'bgr',
686 int_dtype: bool = True):
687 """Get a numpy of colors of shape (N, 3)."""
688 mode = mode.lower()
689 assert set(mode).issubset({'r', 'g', 'b', 'a'})
690 nst0 = np.random.get_state()
691 np.random.seed(flag)
692 colors = []
693 for i in np.arange(0., 360., 360. / number_of_colors):
694 hue = i / 360.
695 lightness = (50 + np.random.rand() * 10) / 100.
696 saturation = (90 + np.random.rand() * 10) / 100.
697 colors.append(colorsys.hls_to_rgb(hue, lightness, saturation))
698 colors_np = np.asarray(colors)
699 if int_dtype:
700 colors_bgr = (255 * colors_np).astype(np.uint8)
701 else:
702 colors_bgr = colors_np.astype(np.float32)
703 # recover the random state
704 np.random.set_state(nst0)
705 color_dict = {}
706 if 'a' in mode:
707 color_dict['a'] = np.ones((colors_bgr.shape[0], 3)) * alpha
708 color_dict['b'] = colors_bgr[:, 0:1]
709 color_dict['g'] = colors_bgr[:, 1:2]
710 color_dict['r'] = colors_bgr[:, 2:3]
711 colors_final = []
712 for channel in mode:
713 colors_final.append(color_dict[channel])
714 colors_final = np.concatenate(colors_final, -1)
715 return colors_final
716
717
718class RunningAverage():

Callers 7

_plot_kp2d_frameFunction · 0.90
_prepare_limb_paletteFunction · 0.90
visualize_kp2dFunction · 0.90
_prepare_colorsFunction · 0.90
visualize_kp3dFunction · 0.90
_export_framesMethod · 0.90
tensor2rgbaMethod · 0.90

Calls 1

concatenateMethod · 0.80

Tested by

no test coverage detected