class documentation

Augmentation that resizes an image with padding to maintain the aspect ratio.

Static Method compute_padding Compute the padding required to resize an image to the letterbox format.
Method __init__ Create a LetterboxResize augmentation.
Method apply Apply the letterbox augmentation to an image.
Method apply_to_bboxes Apply letterbox augmentation to the bounding box.
Method apply_to_keypoints Apply letterbox augmentation to the keypoint.
Method apply_to_mask Apply letterbox augmentation to the input mask.
Method get_params_dependent_on_data Return parameters dependent on input.
Instance Variable height The desired height of the output image.
Instance Variable width The desired width of the output image.
Property targets Define the targets the augmentation will be applied to.
Method _apply_to_image_data Undocumented
Instance Variable _image_fill_value Undocumented
Instance Variable _interpolation Undocumented
Instance Variable _mask_fill_value Undocumented
@staticmethod
def compute_padding(orig_height: int, orig_width: int, out_height: int, out_width: int) -> tuple[int, int, int, int]:

Compute the padding required to resize an image to the letterbox format.

Parameters
orig_height:intOriginal height of the image.
orig_width:intOriginal width of the image.
out_height:intDesired height of the output.
out_width:intDesired width of the output.
Returns
tuple[int, int, int, int]Padding values for the top, bottom, left and right sides of the image.
def __init__(self, height: int, width: int, interpolation: int = cv2.INTER_LINEAR, image_fill_value: Color = 'black', mask_fill_value: int = 0, p: float = 1.0):

Create a LetterboxResize augmentation.

Parameters
height:intThe desired height of the output image
width:intThe desired width of the output image
interpolation:intcv2 flag to specify interpolation used when resizing. Defaults to cv2.INTER_LINEAR.
image_fill_value:ColorPadding value for images. Can be a string color name or an RGB tuple. Defaults to "black".
mask_fill_value:intPadding value for masks. Must be an integer representing a class label. Defaults to 0 (background).
p:floatThe probability of applying the transform. Defaults to 1.0.
@override
def apply(self, img: np.ndarray, pad_top: int, pad_bottom: int, pad_left: int, pad_right: int, **_) -> np.ndarray:

Apply the letterbox augmentation to an image.

Parameters
img:np.ndarrayThe input image of shape (H, W, …) to which the letterbox resize will be applied.
pad_top:intThe number of pixels to pad at the top of the image.
pad_bottom:intThe number of pixels to pad at the bottom of the image.
pad_left:intThe number of pixels to pad on the left side of the image.
pad_right:intThe number of pixels to pad on the right side of the image.
**_Undocumented
Returns
np.ndarrayResized and padded image.
@override
def apply_to_bboxes(self, bbox: np.ndarray, pad_top: int, pad_bottom: int, pad_left: int, pad_right: int, **_) -> np.ndarray:

Apply letterbox augmentation to the bounding box.

Parameters
bbox:np.ndarrayThe input bounding boxes of shape (N, 4 + ) to which the letterbox resize will be applied. Individual bounding boxes should be in the format (xmin, ymin, xmax, ymax, …) and normalized to the range [0, 1]. The trailing dimensions (if any) are not modified by the augmentation.
pad_top:intThe number of pixels to pad at the top of the image.
pad_bottom:intThe number of pixels to pad at the bottom of the image.
pad_left:intThe number of pixels to pad on the left side of the image.
pad_right:intThe number of pixels to pad on the right side of the image.
**_Undocumented
Returns
np.ndarrayTransformed bounding boxes in the same format and normalization as the input.
@override
def apply_to_keypoints(self, keypoint: np.ndarray, pad_top: int, pad_bottom: int, pad_left: int, pad_right: int, orig_height: int, orig_width: int, **_) -> np.ndarray:

Apply letterbox augmentation to the keypoint.

Parameters
keypoint:np.ndarrayThe input keypoints of shape (N, 2 + ) to which the letterbox resize will be applied. Individual keypoints should be in the format (x, y, …) and normalized to the range [0, 1].
pad_top:intThe number of pixels to pad at the top of the image.
pad_bottom:intThe number of pixels to pad at the bottom of the image.
pad_left:intThe number of pixels to pad on the left side of the image.
pad_right:intThe number of pixels to pad on the right side of the image.
orig_height:intOriginal height of the image before resizing.
orig_width:intOriginal width of the image before resizing.
**_Undocumented
Returns
np.ndarrayTransformed keypoints in the same format and normalization as the input. Keypoints that fall outside the image boundaries after transformation will have their coordinates set to  − 1.
@override
def apply_to_mask(self, mask: np.ndarray, pad_top: int, pad_bottom: int, pad_left: int, pad_right: int, **_) -> np.ndarray:

Apply letterbox augmentation to the input mask.

Parameters
mask:np.ndarrayThe input mask of shape (H, W, …) to which the letterbox resize will be applied.
pad_top:intThe number of pixels to pad at the top of the mask.
pad_bottom:intThe number of pixels to pad at the bottom of the mask.
pad_left:intThe number of pixels to pad on the left side of the mask.
pad_right:intThe number of pixels to pad on the right side of the mask.
**_Undocumented
Returns
np.ndarrayResized and padded mask.
@override
def get_params_dependent_on_data(self, params: dict[str, Any], data: dict[str, Any]) -> dict[str, Any]:

Return parameters dependent on input.

Parameters
params:dict[str, Any]The existing augmentation parameters dictionary.
data:dict[str, Any]The dictionary with input data.
Returns
dict[str, Any]A dictionary with extra parameters required for the augmentation, such as padding values and original image dimensions.
height =

The desired height of the output image.

width =

The desired width of the output image.

@property
@override
targets: dict[str, Any] =

Define the targets the augmentation will be applied to.

def _apply_to_image_data(self, img: np.ndarray, pad_top: int, pad_bottom: int, pad_left: int, pad_right: int, interpolation: int, fill_value: RGB) -> np.ndarray:

Undocumented

_image_fill_value =

Undocumented

_interpolation =

Undocumented

_mask_fill_value =

Undocumented