pad_and_scale_annotation

hybrid_learning.datasets.custom.coco.keypoints_processing.pad_and_scale_annotation(ann, from_size, scale=1.0, padding=(0, 0), to_size=None, inplace=False, skip=None)[source]

Given a MS COCO style annotation, apply first padding and/or then scaling to its coordinates. The image transformation operation that is imitated on the annotation is

  1. addition of 0-padding at top, bottom, left, and right.

  2. a rescaling by the given scale=(scale_height, scale_width) factors.

The following coordinate information is adjusted:

  • bounding box (float values)

  • keypoints (float values)

  • segmentation mask (polygon or Run-Length Encoded)

If inplace is True, operate on ann and return it in the end, else operate on a copy which is finally returned. If to_size is given, padding and scale are determined to match the PadAndResize transformation behavior.

Parameters
  • ann (Dict[str, Any]) – the annotation to scale and pad

  • from_size (Tuple[int, int]) – the original size of the image the annotation is for as (height, width) in pixels; can be obtained from the image meta annotation

  • to_size (Optional[Tuple[int, int]]) – the target size as (height, width) to achieve by first scaling then padding; overrides scale and padding

  • scale (Union[float, Tuple[float, float]]) – the scaling factors as (scale_height, scale_width); if one float value is given, a uniform scaling is applied

  • padding (Union[Tuple[int, int], Tuple[int, int, int, int]]) – the padding to apply after rescaling in pixels as (padding_left_right, padding_top_bottom) or (pad_left, pad_right, pad_top, pad_bottom)

  • inplace (bool) – whether to write changes back to ann

  • skip (Optional[Union[str, Sequence[str]]]) – list of strings (or comma separated string concatenation) of any of keypoints, segmentation, bbox; any mentioned information will be excluded from scaling & padding and is left unchanged (may increase speed in case only one type of rescale is needed)

Returns

annotation with coordinate information scaled and padded; a new instance in case inplace is false, else the changed ann