View source: R/item-transforms-random-geometry.R
| item_transform_random_affine | R Documentation |
Draws a random rotation, translation, scale and shear inside the given ranges
and applies the resulting affine transformation to the dataset item with
item_transform_affine, keeping the image size unchanged. Image
and target share the same draw, so that they stay aligned.
item_transform_random_affine(
x,
degrees,
translate = NULL,
scale = NULL,
shear = NULL,
interpolation = 0,
fill = NULL,
center = NULL
)
x |
A dataset item, typically an |
degrees |
(numeric vector of length 2 or numeric): Range of degrees to
select from. If |
translate |
(numeric vector of length 2, optional): Numeric vector of
maximum absolute fraction for horizontal and vertical translations. For
example |
scale |
(numeric vector of length 2, optional): Scaling factor
interval, e.g. |
shear |
(numeric vector or numeric, optional): Range of degrees to
select from. If |
interpolation |
(integer or character, optional): Interpolation mode.
Supported values are |
fill |
Fill color for the area outside the transform. Default is
|
center |
(numeric vector of length 2, optional): Optional center of
rotation, |
The transformation is drawn again for every item, so that a dataset wrapped with this transform yields a different transformation on each access.
A dataset item with the image and target transformed. Detection items
are returned as image_with_rotated_box; segmentation items keep their
class.
Other item_random_transforms:
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_rotation(),
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",
image_height = img$shape[2], image_width = img$shape[3]))
class(before) <- c("image_with_bounding_box", "list")
after <- item_transform_random_affine(before, degrees = 30, translate = c(0.1, 0.1),
scale = c(0.8, 1.2), shear = 10)
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.