dgs.utils.utils.extract_crops_from_images

dgs.utils.utils.extract_crops_from_images(imgs: list[torchvision.tv_tensors.Image | torch.Tensor], bboxes: torchvision.tv_tensors.BoundingBoxes, kps: torch.Tensor | None = None, **kwargs) tuple[torchvision.tv_tensors.Image | torch.Tensor, torch.Tensor | None][source]

Given a list of images, use the bounding boxes to extract the respective image crops. Additionally, compute the local key-point coordinates if global key points are given.

Parameters:
  • imgs – A list containing one or multiple tv_tensors.Image tensors.

  • bboxes – The bounding boxes as tv_tensors.BoundingBoxes of arbitrary format.

  • kps – The key points of the respective images. The key points will be transformed with the images to obtain the local key point coordinates. Default None just means that a placeholder is passed and returned.

Keyword Arguments:
  • crop_size (ImgShape) – The target shape of the image crops. Defaults to DEF_VAL.images.crop_size.

  • transform (tvt.Compose) – A torchvision transform given as Compose to get the crops from the original image. Defaults to a version of CustomCropResize.

  • crop_mode (str) – Defines the resize mode in the transform function. Has to be in the modes of CustomToAspect. Default DEF_VAL.images.mode.

Returns:

The 4D image crop(s) with the same format as the image, as tv_tensors of shape [N x C x H x W]. The local key points are returned iff kps was not None.