draw_segmentation_masks: Draw segmentation masks

View source: R/vision_utils.R

draw_segmentation_masksR Documentation

Draw segmentation masks

Description

Draw segmentation masks with their respective colors on top of a given RGB tensor image

Usage

draw_segmentation_masks(image, masks, alpha = 0.8, colors = NULL)

Arguments

image

: torch_tensor of shape (3, H, W) and dtype uint8.

masks

: torch_tensor of shape (num_masks, H, W) or (H, W) and dtype bool.

alpha

: number between 0 and 1 denoting the transparency of the masks.

colors

: character vector containing the colors of the boxes or single color for all boxes. The color can be represented as strings e.g. "red" or "#FF00FF". By default, viridis colors are generated for masks

Value

torch_tensor of shape (3, H, W) and dtype uint8 of the image with segmentation masks drawn on top.

Examples

if (torch::torch_is_installed()) {
image <- torch::torch_randint(170, 250, size = c(3, 360, 360))$to(torch::torch_uint8())
mask <- torch::torch_tril(torch::torch_ones(c(360, 360)))$to(torch::torch_bool())
masked_image <- draw_segmentation_masks(image, mask, alpha = 0.2)
tensor_image_browse(masked_image)
}

torchvision documentation built on June 22, 2024, 11:25 a.m.