class documentation

Batch-based augmentation that creates a mosaic of four images.

The transform arranges four images in a deterministic 2×2 grid:

1 2
3 4

Images may have different sizes, but they must have the same number of channels. The result is cropped around the mosaic center to out_width by out_height and padded when needed with the specified fill values.

https://github.com/luxonis/luxonis-ml/blob/58fb10adc38a393640b9dc889fdefd1db81f9900/luxonis_ml/data/augmentations/media/mosaic4.png

An example of the Mosaic4 augmentation.

Method __init__ Create a Mosaic4 augmentation.
Method apply Apply mosaic augmentation to a batch of images.
Method apply_to_bboxes Apply mosaic augmentation to a batch of bounding boxes.
Method apply_to_instance_mask Apply mosaic augmentation to a batch of instance segmentation masks.
Method apply_to_keypoints Apply mosaic augmentation to a batch of keypoints.
Method apply_to_mask Apply mosaic augmentation to a batch of semantic segmentation masks.
Method generate_random_crop_center Generate a random crop center within the bounds of the mosaic image size.
Method get_params_dependent_on_data Get parameters dependent on the targets.
Static Method _apply_mosaic4_to_bboxes Adjust bounding box coordinates for the mosaic grid position.
Static Method _apply_mosaic4_to_images Arrange the images in a 2×2 grid layout.
Static Method _apply_mosaic4_to_instance_masks Undocumented
Static Method _apply_mosaic4_to_keypoints Adjust keypoint coordinates for the mosaic grid position.
Static Method _compute_mosaic4_corners Undocumented
Static Method _compute_shifts_for_quadrant Undocumented
Instance Variable _height Undocumented
Instance Variable _image_fill_value Undocumented
Instance Variable _mask_fill_value Undocumented
Instance Variable _width Undocumented

Inherited from BatchTransform:

Method apply_to_array Apply the transformation to a batch of generic arrays.
Method apply_to_classification Apply the transformation to a batch of classification labels.
Method apply_to_metadata Apply the transformation to a batch of metadata arrays.
Method update_transform_params Update the parameters dictionary with the shape of the input images.
Instance Variable batch_size Number of samples consumed by one application of the transform.
Property targets Undocumented
@deprecated('out_height', 'out_width', 'value', 'mask_value', suggest={'out_height': 'height', 'out_width': 'width', 'value': 'image_fill_value', 'mask_value': 'mask_fill_value'})
def __init__(self, height: int | None = None, width: int | None = None, image_fill_value: float | list[int] | list[float] | None = None, mask_fill_value: float | list[int] | list[float] | None = None, p: float = 0.5, out_height: int | None = None, out_width: int | None = None, value: float | list[int] | list[float] | None = None, mask_value: float | list[int] | list[float] | None = None):

Create a Mosaic4 augmentation.

Parameters
height:int | NoneOutput image height.
width:int | NoneOutput image width.
image_fill_value:float | list[int] | list[float] | NonePadding value for images.
mask_fill_value:float | list[int] | list[float] | NonePadding value for masks.
p:floatProbability of applying the transform.
out_height:int | None
Deprecated since version 0.9.0: Use height instead.
out_width:int | None
Deprecated since version 0.9.0: Use width instead.
value:float | list[int] | list[float] | None
Deprecated since version 0.9.0: Use image_fill_value instead.
mask_value:float | list[int] | list[float] | None
Deprecated since version 0.9.0: Use mask_fill_value instead.
Raises
ValueErrorIf the resolved output height or width is missing or not greater than 0.
@override
def apply(self, image_batch: list[np.ndarray], x_crop: int, y_crop: int, **_) -> np.ndarray:

Apply mosaic augmentation to a batch of images.

Parameters
image_batch:list[np.ndarray]Images to transform. Each image should be of shape (H, W, C) or (H, W).
x_crop:intX-coordinate of the crop start point.
y_crop:intY-coordinate of the crop start point.
**_Undocumented
Returns
np.ndarrayA single image of shape (Hout, Wout, C) or (Hout, Wout).
@override
def apply_to_bboxes(self, bboxes_batch: list[np.ndarray], image_shapes: list[tuple[int, int]], x_crop: int, y_crop: int, **_) -> np.ndarray:

Apply mosaic augmentation to a batch of bounding boxes.

Parameters
bboxes_batch:list[np.ndarray]Bounding boxes to transform.
image_shapes:list[tuple[int, int]]Original image shapes.
x_crop:intX-coordinate of the crop start point.
y_crop:intY-coordinate of the crop start point.
**_Undocumented
Returns
np.ndarrayTransformed bounding boxes.
@override
def apply_to_instance_mask(self, masks_batch: list[np.ndarray], x_crop: int, y_crop: int, **_) -> np.ndarray:

Apply mosaic augmentation to a batch of instance segmentation masks.

Parameters
masks_batch:list[np.ndarray]Masks to transform. Each mask should be of shape (H, W, N), where N is the number of instances.
x_crop:intX-coordinate of the crop start point.
y_crop:intY-coordinate of the crop start point.
**_Undocumented
Returns
np.ndarrayA single instance masks of shape (Hout, Wout, N).
@override
def apply_to_keypoints(self, keypoints_batch: list[np.ndarray], image_shapes: list[tuple[int, int]], x_crop: int, y_crop: int, **_) -> np.ndarray:

Apply mosaic augmentation to a batch of keypoints.

Parameters
keypoints_batch:list[np.ndarray]Keypoints to transform.
image_shapes:list[tuple[int, int]]Original image shapes.
x_crop:intX-coordinate of the crop start point.
y_crop:intY-coordinate of the crop start point.
**_Undocumented
Returns
np.ndarrayTransformed keypoints.
@override
def apply_to_mask(self, mask_batch: list[np.ndarray], x_crop: int, y_crop: int, out_height: int, out_width: int, **_) -> np.ndarray:

Apply mosaic augmentation to a batch of semantic segmentation masks.

Parameters
mask_batch:list[np.ndarray]Masks to transform. Each mask should be of shape (H, W, C) or (H, W).
x_crop:intX-coordinate of the crop start point.
y_crop:intY-coordinate of the crop start point.
out_height:intThe expected height of the output mask.
out_width:intThe expected width of the output mask.
**_Undocumented
Returns
np.ndarrayA single segmentation mask of shape (Hout, Wout, C) or (Hout, Wout).
def generate_random_crop_center(self) -> tuple[int, int]:

Generate a random crop center within the bounds of the mosaic image size.

@override
def get_params_dependent_on_data(self, params: dict[str, Any], data: dict[str, Any]) -> dict[str, Any]:

Get parameters dependent on the targets.

Parameters
params:dict[str, Any]Existing augmentation parameters.
data:dict[str, Any]Input data.
Returns
dict[str, Any]Parameters derived from the input targets.
@staticmethod
def _apply_mosaic4_to_bboxes(bbox: np.ndarray, in_height: int, in_width: int, position_index: int, out_height: int, out_width: int, x_crop: int, y_crop: int) -> np.ndarray:

Adjust bounding box coordinates for the mosaic grid position.

@staticmethod
def _apply_mosaic4_to_images(image_batch: list[np.ndarray], out_height: int, out_width: int, x_crop: int, y_crop: int, padding: float | list[int] | list[float] | None = None) -> np.ndarray:

Arrange the images in a 2×2 grid layout.

The input images should have the same number of channels but can have different widths and heights. The gaps are filled by the padding value.

@staticmethod
def _apply_mosaic4_to_instance_masks(masks_batch: list[np.ndarray], out_height: int, out_width: int, x_crop: int, y_crop: int, value: float | list[int] | list[float] | None = None) -> np.ndarray:

Undocumented

@staticmethod
def _apply_mosaic4_to_keypoints(keypoints: np.ndarray, in_height: int, in_width: int, position_index: int, out_height: int, out_width: int, x_crop: int, y_crop: int) -> np.ndarray:

Adjust keypoint coordinates for the mosaic grid position.

@staticmethod
def _compute_mosaic4_corners(quadrant: int, out_height: int, out_width: int, in_height: int, in_width: int) -> tuple[tuple[int, int, int, int], tuple[int, int, int, int]]:

Undocumented

@staticmethod
def _compute_shifts_for_quadrant(position_index: int, in_height: int, in_width: int, out_height: int, out_width: int) -> tuple[int, int]:

Undocumented

_height =

Undocumented

_image_fill_value =

Undocumented

_mask_fill_value =

Undocumented

_width =

Undocumented