Applies 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.

target_transform_affine(
  target,
  angle = 0,
  translate = c(0, 0),
  scale = 1,
  shear = 0,
  center = NULL
)

# S3 method for class 'object_detection_target'
target_transform_affine(
  target,
  angle = 0,
  translate = c(0, 0),
  scale = 1,
  shear = 0,
  center = NULL
)

Arguments

target

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

angle

(numeric): Rotation angle value in degrees, counter-clockwise.

translate

(integer vector of length 2): Horizontal and vertical translations (post-rotation translation).

scale

(numeric): Overall scale.

shear

(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.

center

(numeric vector of length 2, optional): Optional center of rotation, c(x, y). Default is image center.

Value

A list with the same structure as the input target, where boxes is a tensor of shape (N, 5) in xyxyr format.

See also

Examples

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)
} # }