View source: R/item-transforms-geometry.R
| item_transform_rotate | R Documentation |
Rotates a dataset item by a given angle around its center. The canvas is expanded so that the entire rotated image is visible with no cropping. Empty regions are filled with given fill color.
item_transform_rotate(x, angle, interpolation = 2, expand = TRUE, fill = 0)
x |
A dataset item, typically an |
angle |
(numeric): Rotation angle value in degrees, counter-clockwise. |
interpolation |
(integer, optional): Interpolation mode. |
expand |
(logical, optional): Optional expansion flag. If |
fill |
(numeric vector or numeric): Pixel fill value for area outside
the rotated image. If a single numeric value, the value is used for all
channels. Defaults to |
The bounding boxes (if present) are rotated around the original image centre and shifted onto the (possibly expanded) output canvas, while their physical size is left unchanged. The result is always in xyxyr format with the accumulated rotation angle. For segmentation items, the masks are rotated alongside the image using nearest-neighbour sampling.
A dataset item with the image and target rotated. Detection items are
returned as image_with_rotated_box with boxes in xyxyr format;
segmentation items keep their class.
Other item_unitary_transforms:
item_transform_affine(),
item_transform_center_crop(),
item_transform_crop(),
item_transform_hflip(),
item_transform_pad(),
item_transform_perspective(),
item_transform_resize(),
item_transform_vflip()
## Not run:
url <- "https://upload.wikimedia.org/wikipedia/commons/b/b6/Felis_catus-cat_on_snow.jpg"
angle <- 30
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_rotate(before, angle = angle)
before_plot <- draw_bounding_boxes(before, colors = "blue", width = 10)
after_plot <- draw_bounding_boxes(after, colors = "red", width = 10)
grid <- vision_make_grid(transform_resize(before_plot, c(600, 600)),
transform_resize(after_plot, c(600, 600)),
scale = TRUE
)
tensor_image_browse(grid)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.