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
addition of 0-padding at top, bottom, left, and right.
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
isTrue
, operate onann
and return it in the end, else operate on a copy which is finally returned. Ifto_size
is given,padding
andscale
are determined to match thePadAndResize
transformation behavior.- Parameters
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 annotationto_size (Optional[Tuple[int, int]]) – the target size as
(height, width)
to achieve by first scaling then padding; overridesscale
andpadding
scale (Union[float, Tuple[float, float]]) – the scaling factors as
(scale_height, scale_width)
; if one float value is given, a uniform scaling is appliedpadding (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 changedann