MCPcopy Create free account
hub / github.com/open-mmlab/mmengine / color_val_matplotlib

Function color_val_matplotlib

mmengine/visualization/utils.py:94–120  ·  view source on GitHub ↗

Convert various input in RGB order to normalized RGB matplotlib color tuples, Args: colors (Union[str, tuple, List[Union[str, tuple]]]): Color inputs Returns: Union[str, tuple, List[Union[str, tuple]]]: A tuple of 3 normalized floats indicating RGB channels.

(
    colors: Union[str, tuple, List[Union[str, tuple]]]
)

Source from the content-addressed store, hash-verified

92
93
94def color_val_matplotlib(
95 colors: Union[str, tuple, List[Union[str, tuple]]]
96) -> Union[str, tuple, List[Union[str, tuple]]]:
97 """Convert various input in RGB order to normalized RGB matplotlib color
98 tuples,
99 Args:
100 colors (Union[str, tuple, List[Union[str, tuple]]]): Color inputs
101 Returns:
102 Union[str, tuple, List[Union[str, tuple]]]: A tuple of 3 normalized
103 floats indicating RGB channels.
104 """
105 if isinstance(colors, str):
106 return colors
107 elif isinstance(colors, tuple):
108 assert len(colors) == 3
109 for channel in colors:
110 assert 0 <= channel <= 255
111 colors = [channel / 255 for channel in colors]
112 return tuple(colors)
113 elif isinstance(colors, list):
114 colors = [
115 color_val_matplotlib(color) # type:ignore
116 for color in colors
117 ]
118 return colors
119 else:
120 raise TypeError(f'Invalid type for color: {type(colors)}')
121
122
123def color_str2rgb(color: str) -> tuple:

Callers 5

draw_pointsMethod · 0.90
draw_textsMethod · 0.90
draw_linesMethod · 0.90
draw_circlesMethod · 0.90
draw_polygonsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…