annotation

Some utility functions for annotating PIL Images

source

draw_masks

 draw_masks (image:<module'PIL.Image'from'/opt/hostedtoolcache/Python/3.9.
             18/x64/lib/python3.9/site-packages/PIL/Image.py'>,
             masks:numpy.ndarray, labels:list, colors:list,
             conf_threshold:float, alpha:float=0.3)

Annotates an image with segmentation masks, labels, and optional alpha blending.

This function draws segmentation masks on the provided image using the given mask arrays, colors, labels, and alpha values for transparency.

Type Default Details
image PIL.Image The input image on which annotations will be drawn.
masks ndarray A 3D numpy array of shape (n_masks, height, width) representing segmentation masks.
labels list A list of labels corresponding to each segmentation mask.
colors list A list of RGB tuples for each segmentation mask and its corresponding label.
conf_threshold float The threshold value to convert mask to binary.
alpha float 0.3 The alpha value for mask transparency.
Returns PIL.Image The image annotated with segmentation masks and labels.

source

draw_bboxes

 draw_bboxes (image:<module'PIL.Image'from'/opt/hostedtoolcache/Python/3.9
              .18/x64/lib/python3.9/site-packages/PIL/Image.py'>,
              boxes:list, labels:list, colors:list, font:str,
              box_format:str='xywh', width:int=2, font_size:int=18,
              probs:int=None)

Annotates an image with bounding boxes, labels, and optional probability scores.

This function draws bounding boxes on the provided image using the given box coordinates, colors, and labels. If probabilities are provided, they will be added to the labels.

Type Default Details
image PIL.Image The input image on which annotations will be drawn.
boxes list A list of bounding box coordinates. The format is determined by box_format.
labels list A list of labels corresponding to each bounding box.
colors list A list of colors for each bounding box and its corresponding label.
font str Path to the font file to be used for displaying the labels.
box_format str xywh The format of the bounding boxes (“xywh” for [x, y, w, h], “xyxy” for [x1, y1, x2, y2],or “cxywh” for [center-x, center-y, width, height]). Defaults to “xywh”.
width int 2 Width of the bounding box lines.
font_size int 18 Size of the font for the labels.
probs int None A list of probability scores corresponding to each label.
Returns PIL.Image The image annotated with bounding boxes, labels, and optional probability scores.