R/target-transforms-detection.R
target_transform_affine.RdApplies an affine transformation (rotation, translation, scale and shear) to
the bounding boxes of a detection target so that they follow an image
transformed by transform_affine() with the same parameters. Each box centre
is moved by the affine transformation around the given centre, the box is
scaled by scale and rotated by angle, and the result is returned as a
rotated box in xyxyr format. Passing an already rotated target accumulates the
rotation, so transforms compose.
An object_detection_target, as returned by the .getitem()
method of an object detection dataset, or a bare list containing
at least:
boxes — tensor of shape (N, 4) in xyxy format, or (N, 5) in
xyxyr format for an already rotated target
image_height — original image height, defining the rotation centre
image_width — original image width, defining the rotation centre
Other fields (labels, etc.) are preserved unchanged
(numeric): Rotation angle value in degrees, counter-clockwise.
(integer vector of length 2): Horizontal and vertical translations (post-rotation translation).
(numeric): Overall scale.
(numeric vector or numeric): Shear angle value in degrees
between -180 to 180, clockwise direction. If a numeric vector is
specified, the first value corresponds to a shear parallel to the x-axis,
while the second value corresponds to a shear parallel to the y-axis.
(numeric vector of length 2, optional): Optional center of
rotation, c(x, y). Default is image center.
A list with the same structure as the input target, where boxes is a
tensor of shape (N, 5) in xyxyr format.
Other target_transforms_detection:
prepare_sahi_split(),
target_transform_resize(),
target_transform_rotate()
if (FALSE) { # \dontrun{
target <- list(
boxes = torch_tensor(matrix(c(10, 20, 50, 60), ncol = 4), dtype = torch_float32()),
labels = torch_tensor(1L, dtype = torch_long()),
image_height = 100L,
image_width = 200L
)
class(target) <- c("object_detection_target", "list")
target_transform_affine(target, angle = 20, translate = c(10, 5), scale = 1.1, shear = 8)
} # }