draw_bounding_boxes: Draws bounding boxes on image.

View source: R/vision_utils.R

draw_bounding_boxesR Documentation

Draws bounding boxes on image.

Description

Draws bounding boxes on top of one image tensor

Usage

draw_bounding_boxes(
  image,
  boxes,
  labels = NULL,
  colors = NULL,
  fill = FALSE,
  width = 1,
  font = c("serif", "plain"),
  font_size = 10
)

Arguments

image

: Tensor of shape (C x H x W) and dtype uint8.

boxes

: Tensor of size (N, 4) containing bounding boxes in (xmin, ymin, xmax, ymax) format. Note that the boxes are absolute coordinates with respect to the image. In other words: ⁠0 = xmin < xmax < W⁠ and ⁠0 = ymin < ymax < H⁠.

labels

: character vector containing the labels of bounding boxes.

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 boxes.

fill

: If TRUE fills the bounding box with specified color.

width

: Width of text shift to the bounding box.

font

: NULL for the current font family, or a character vector of length 2 for Hershey vector fonts.

font_size

: The requested font size in points.

Value

torch_tensor of size (C, H, W) of dtype uint8: Image Tensor with bounding boxes plotted.

See Also

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

Examples

if (torch::torch_is_installed()) {
## Not run: 
image <- torch::torch_randint(170, 250, size = c(3, 360, 360))$to(torch::torch_uint8())
x <- torch::torch_randint(low = 1, high = 160, size = c(12,1))
y <- torch::torch_randint(low = 1, high = 260, size = c(12,1))
boxes <- torch::torch_cat(c(x, y, x + 20, y +  10), dim = 2)
bboxed <- draw_bounding_boxes(image, boxes, colors = "black", fill = TRUE)
tensor_image_browse(bboxed)

## End(Not run)
}

mlverse/torchvision documentation built on Sept. 18, 2024, 4:03 p.m.