Draws bounding boxes on top of one image tensor
draw_bounding_boxes(x, ...)
# Default S3 method
draw_bounding_boxes(x, ...)
# S3 method for class 'torch_tensor'
draw_bounding_boxes(
x,
boxes,
labels = NULL,
colors = NULL,
fill = FALSE,
width = 1,
font = c("serif", "plain"),
font_size = 10,
lazy = TRUE,
...
)
# S3 method for class 'image_with_bounding_box'
draw_bounding_boxes(x, ...)
# S3 method for class 'image_with_rotated_box'
draw_bounding_boxes(x, labels = NULL, ...)A torch_tensor of shape (C x H x W) and dtype uint8 or dtype float,
an image_with_bounding_box, or an image_with_rotated_box object.
In case of a tensor with 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.
Tensor of size (N, 4) containing N bounding boxes in c(\(x_{min}\), \(y_{min}\), \(x_{max}\), \(y_{max}\)). format. Note that the boxes coordinates are absolute with respect to the image. In other words: \(0 \leq x_{min} < x_{max} < Height \) and \(0 \leq y_{min} < y_{max} < Width \).
A character vector or tensor containing one label for all boxes,
or one label per box in the original boxes tensor.
character vector containing the colors
of the boxes or single color for all boxes. When supplying multiple colors,
provide one per box in the original boxes tensor. The color can be represented as
strings e.g. "red" or "#FF00FF". By default, viridis colors are generated for boxes.
If TRUE fills the bounding box with specified color.
Width of text shift to the bounding box.
NULL for the current font family, or a character vector of length 2 for Hershey vector fonts.
The requested font size in points.
if TRUE, silently filter out degenerate bounding boxes (xmin >= xmax or ymin >= ymax).
Corresponding per-box labels and colors are filtered with the boxes.
If FALSE, error on the first non-conforming box.
torch_tensor of size (C, H, W) of dtype uint8: Image Tensor with bounding boxes plotted.
Other image display:
draw_keypoints(),
draw_segmentation_masks(),
tensor_image_browse(),
tensor_image_display(),
vision_make_grid()
if (torch::torch_is_installed()) {
if (FALSE) { # \dontrun{
image_tensor <- 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_tensor, boxes, colors = "black", labels = "label", fill = TRUE)
tensor_image_browse(bboxed)
} # }
}