Undocumented
| Class | |
A mapping that assigns distinct RGB colors to hashable labels. |
| Function | add |
Append the applied augmentations as a footer below the image. |
| Function | append |
Append a multi-line text block below the image. |
| Function | concat |
Concatenate images into a single labeled image. |
| Function | create |
Create an image with centered text. |
| Function | distinct |
Generate distinct RGB colors using the golden ratio. |
| Function | draw |
Draw the class name label at the top-left corner of the bounding box. |
| Function | draw |
Draw a cross on the image. |
| Function | draw |
Draw a dashed rectangle on the image. |
| Function | draw |
Draw a text label next to a keypoint on the image. |
| Function | get |
Return a contrasting color for the given RGB color. |
| Function | hsv |
Convert an HSV color to RGB. |
| Function | resolve |
Resolve a color to RGB. |
| Function | rgb |
Convert an RGB color to HSV. |
| Function | str |
Convert a string to its deterministic RGB color. |
| Function | visualize |
Visualize labels on the image. |
| Function | wrap |
Wrap text into lines that fit within the given width. |
np.ndarray, lines: list[ str], font_scale: float, bg_color: Color = (Color = (np.ndarray:
¶
Append a multi-line text block below the image.
dict[ str, np.ndarray], padding: int = 10, label_height: int = 30) -> np.ndarray:
¶
Concatenate images into a single labeled image.
It will attempt to create a square grid of images.
| Parameters | |
imagedict[ | Mapping of image names to images. |
padding:int | Padding between images. |
labelint | Height of each label. |
| Returns | |
np.ndarray | The concatenated image. |
Generate distinct RGB colors using the golden ratio.
This generator produces a sequence of distinct colors in RGB format. The colors are generated by incrementing the hue by the golden ratio and keeping saturation and value fixed. This ensures a wide distribution of visually distinct colors.
Examples
>>> colors = list(distinct_color_generator(stop=2)) >>> len(colors) 2 >>> all(len(color) == 3 for color in colors) True
| Parameters | |
stop:int | optional maximum number of colors to generate. If set to − 1, the generator continues indefinitely. |
| Returns | |
Generator[ | Undocumented |
| Yields | |
| The next RGB color with each component in the range [0, 255]. |
np.ndarray, class_name: str, box: np.ndarray, color: tuple[ int, int, int], font_scale: float):
¶
Draw the class name label at the top-left corner of the bounding box.
| Parameters | |
image:np.ndarray | Image to draw on. |
classstr | Name of the class. |
box:np.ndarray | Bounding box coordinates in [class_id, x1, y1, x2, y2] format, where (x1, y1) is the top-left corner and (x2, y2) is the bottom-right corner. |
color:tuple[ | Label color. |
fontfloat | Font scale. |
np.ndarray, center: tuple[ int, int], size: int = 5, color: Color = 0, thickness: int = 1):
¶
Draw a cross on the image.
| Parameters | |
img:np.ndarray | Image to draw on. |
center:tuple[ | Center of the cross. |
size:int | Size of the cross. |
color:Color | Cross color. |
thickness:int | Line thickness. |
np.ndarray, pt1: tuple[ int, int], pt2: tuple[ int, int], color: Color, thickness: int = 1, dash_length: int = 10):
¶
Draw a dashed rectangle on the image.
| Parameters | |
image:np.ndarray | Image to draw on. |
pt1:tuple[ | Top-left corner of the rectangle. |
pt2:tuple[ | Bottom-right corner of the rectangle. |
color:Color | Rectangle color. |
thickness:int | Line thickness. |
dashint | Length of each dash. |
np.ndarray, text: str, point: tuple[ int, int], size: int, color: tuple[ int, int, int], font_scale: float):
¶
Draw a text label next to a keypoint on the image.
| Parameters | |
image:np.ndarray | Image to draw on. |
text:str | Text to draw. |
point:tuple[ | Keypoint coordinates. |
size:int | Keypoint size. |
color:tuple[ | Text color. |
fontfloat | Font scale. |
Resolve a color to RGB.
Examples
>>> resolve_color(12) (12, 12, 12) >>> resolve_color((1, 2, 3)) (1, 2, 3) >>> resolve_color(300) Traceback (most recent call last): ... ValueError: Color value 300 is out of range [0, 255]
| Parameters | |
color:Color | Color to resolve. |
| Returns | |
RGB | The resolved RGB color. |
| Raises | |
ValueError | If an integer channel value is outside [0, 255]. |
Convert a string to its deterministic RGB color.
Examples
>>> str_to_rgb("car") == str_to_rgb("car") True >>> len(str_to_rgb("car")) 3
| Parameters | |
string:str | String to convert. |
| Returns | |
RGB | Deterministic RGB color. |
np.ndarray, source_name: str, labels: Labels, classes: dict[ str, dict[ str, int]], blend_all: bool = False, categorical_encodings: dict[ str, dict[ str, int]] | None = None) -> np.ndarray:
¶
Visualize labels on the image.
| Parameters | |
image:np.ndarray | Image to visualize. |
sourcestr | Name of the image source. |
labels:Labels | Labels to visualize. |
classes:dict[ | Mapping from task names to class ID mappings. |
blendbool | Whether to blend all labels into a single image. This mixes labels that belong to different tasks. |
categoricaldict[ | optional mapping for categorical metadata tasks. Keys are full task identifiers such as "task_name/metadata/key" and values map string labels to encoded integers. |
| Returns | |
np.ndarray | The visualized image. |