Resizes the image inside a dataset item. For detection items, bounding box coordinates are rescaled by the same factors as the image. For segmentation items, the masks are resized alongside the image with nearest-neighbour sampling, so that they keep their discrete values.
item_transform_resize(x, size, interpolation = 2)A dataset item, typically an image_with_bounding_box or
image_with_segmentation_mask object containing an image tensor
and associated target data.
(integer vector or integer): Desired output size. If size is
an integer vector of length 2 like c(h, w), output size will be matched
to this. If size is a bare integer, smaller edge of the image will be
matched to this number, i.e., if height > width, then image will be
rescaled to (size * height / width, size).
(integer, optional): Desired interpolation. An integer
0 = nearest, 2 = bilinear, and 3 = bicubic or a name from
magick::filter_types().
A dataset item of the same class with the image and target resized.
if (FALSE) { # \dontrun{
url <- "https://upload.wikimedia.org/wikipedia/commons/b/b6/Felis_catus-cat_on_snow.jpg"
img <- base_loader(url) |> transform_to_tensor()
boxes <- torch_tensor(matrix(c(600, 200, 2880, 1860), ncol = 4), dtype = torch_float32())
before <- list(x = img, y = list(boxes = boxes, labels = "cat"))
class(before) <- c("image_with_bounding_box", "list")
after <- item_transform_resize(before, size = c(600, 800))
before_plot <- draw_bounding_boxes(before, colors = "blue", width = 10)
after_plot <- draw_bounding_boxes(after, colors = "red", width = 10)
tensor_image_browse(before_plot)
tensor_image_browse(after_plot)
} # }