Shortcuts

draw_segmentation_masks

torchvision.utils.draw_segmentation_masks(image: torch.Tensor, masks: torch.Tensor, alpha: float = 0.8, colors: Optional[Union[List[Union[str, Tuple[int, int, int]]], str, Tuple[int, int, int]]] = None)torch.Tensor[source]

Draws segmentation masks on given RGB image. The values of the input image should be uint8 between 0 and 255.

Parameters
  • image (Tensor) – Tensor of shape (3, H, W) and dtype uint8.

  • masks (Tensor) – Tensor of shape (num_masks, H, W) or (H, W) and dtype bool.

  • alpha (float) – Float number between 0 and 1 denoting the transparency of the masks. 0 means full transparency, 1 means no transparency.

  • colors (color or list of colors, optional) – List containing the colors of the masks or single color for all masks. The color can be represented as PIL strings e.g. “red” or “#FF00FF”, or as RGB tuples e.g. (240, 10, 157). By default, random colors are generated for each mask.

Returns

Image Tensor, with segmentation masks drawn on top.

Return type

img (Tensor[C, H, W])

Examples using draw_segmentation_masks:

Repurposing masks into bounding boxes

Repurposing masks into bounding boxes

Repurposing masks into bounding boxes
Visualization utilities

Visualization utilities

Visualization utilities

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources