Learn R Programming

torchvision (version 0.7.0)

draw_segmentation_masks: Draw segmentation masks

Description

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

Usage

draw_segmentation_masks(x, ...)

# S3 method for default draw_segmentation_masks(x, ...)

# S3 method for torch_tensor draw_segmentation_masks(x, masks, alpha = 0.8, colors = NULL, ...)

# S3 method for image_with_segmentation_mask draw_segmentation_masks(x, alpha = 0.5, colors = NULL, ...)

Value

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

Arguments

x

Tensor of shape (C x H x W) and dtype uint8 or dtype float. In case of dtype float, values are assumed to be in range \([0, 1]\). C value for channel can only be 1 (grayscale) or 3 (RGB).

...

Additional arguments passed to methods.

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

See Also

Other image display: draw_bounding_boxes(), draw_keypoints(), tensor_image_browse(), tensor_image_display(), vision_make_grid()

Examples

Run this code
if (torch::torch_is_installed()) {
image_tensor <- 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_tensor, mask, alpha = 0.2)
tensor_image_browse(masked_image)
}

Run the code above in your browser using DataLab