# mosaic

Python API: `luxonis_ml.data.augmentations.custom.mosaic`

## Classes

### Mosaic4

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

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

| Column 1 | Column 2 |
| --- | --- |
| 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.

An example of the Mosaic4 augmentation.

> **See Also**
> [Dynamic Scale Training for Object Detection](https://arxiv.org/abs/2004.12432)

#### Methods

##### init

```python
def __init__(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 | None`): Output image height.
 * `width` (`int | None`): Output image width.
 * `image_fill_value` (`float | list[int] | list[float] | None`): Padding value for images.
 * `mask_fill_value` (`float | list[int] | list[float] | None`): Padding value for masks.
 * `p` (`float`): Probability of applying the transform.
 * `out_height` (`int | None`):> **Deprecated**
   > Deprecated since version 0.9.0:Use `height` instead.
 * `out_width` (`int | None`):> **Deprecated**
   > Deprecated since version 0.9.0:Use `width` instead.
 * `value` (`float | list[int] | list[float] | None`):> **Deprecated**
   > Deprecated since version 0.9.0:Use `image_fill_value` instead.
 * `mask_value` (`float | list[int] | list[float] | None`):> **Deprecated**
   > Deprecated since version 0.9.0:Use `mask_fill_value` instead.

Raises

 * `ValueError`: If the resolved output height or width is missing or not greater than 0.

##### apply

```python
def apply(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` (`int`): X-coordinate of the crop start point.
 * `y_crop` (`int`): Y-coordinate of the crop start point.
 * `**_`

Returns

 * `np.ndarray`: A single image of shape (Hout, Wout, C) or (Hout, Wout).

##### apply_to_bboxes

```python
def apply_to_bboxes(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` (`int`): X-coordinate of the crop start point.
 * `y_crop` (`int`): Y-coordinate of the crop start point.
 * `**_`

Returns

 * `np.ndarray`: Transformed bounding boxes.

##### apply_to_instance_mask

```python
def apply_to_instance_mask(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` (`int`): X-coordinate of the crop start point.
 * `y_crop` (`int`): Y-coordinate of the crop start point.
 * `**_`

Returns

 * `np.ndarray`: A single instance masks of shape (Hout, Wout, N).

##### apply_to_keypoints

```python
def apply_to_keypoints(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` (`int`): X-coordinate of the crop start point.
 * `y_crop` (`int`): Y-coordinate of the crop start point.
 * `**_`

Returns

 * `np.ndarray`: Transformed keypoints.

##### apply_to_mask

```python
def apply_to_mask(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` (`int`): X-coordinate of the crop start point.
 * `y_crop` (`int`): Y-coordinate of the crop start point.
 * `out_height` (`int`): The expected height of the output mask.
 * `out_width` (`int`): The expected width of the output mask.
 * `**_`

Returns

 * `np.ndarray`: A single segmentation mask of shape (Hout, Wout, C) or (Hout, Wout).

##### generate_random_crop_center

```python
def generate_random_crop_center(self) -> tuple[int, int]:
```

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

##### get_params_dependent_on_data

```python
def get_params_dependent_on_data(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.
