View source: R/item-transforms-random-geometry.R
| item_transform_random_rotation | R Documentation |
Draws a random angle inside the given range and rotates the dataset item by
that angle with item_transform_rotate. Image and target share
the same draw, so that boxes and masks stay aligned with the rotated image.
item_transform_random_rotation(
x,
degrees,
interpolation = 2,
expand = FALSE,
fill = 0
)
x |
A dataset item, typically an |
degrees |
(numeric vector of length 2 or numeric): Range of degrees to
select from. If |
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 angle is drawn again for every item, so that a dataset wrapped with this
transform yields a different rotation on each access. Unlike
item_transform_rotate, the canvas is not expanded by default, so
that every item keeps the size it had and a wrapped dataset can still be
collated into batches. Pass expand = TRUE to hold the whole rotated
image instead.
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_random_transforms:
item_transform_random_affine(),
item_transform_random_crop(),
item_transform_random_erasing(),
item_transform_random_horizontal_flip(),
item_transform_random_perspective(),
item_transform_random_resize_crop(),
item_transform_random_vertical_flip()
## Not run:
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_random_rotation(before, degrees = 30)
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)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.