# mosaic

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

## 类

### Mosaic4

基于批次的增强，创建四张图像的马赛克。

该变换以确定的 2×2 网格排列四张图像：

| 第 1 列 | 第 2 列 |
| --- | --- |
| 1 | 2 |
| 3 | 4 |

图像可以有不同的大小，但它们必须具有相同的通道数。结果将围绕马赛克中心裁剪为 `out_width` 乘以 `out_height`，并在需要时用指定的填充值进行填充。

Mosaic4 增强的一个示例。

> **另请参阅**
> [用于目标检测的动态尺度训练](https://arxiv.org/abs/2004.12432)

#### 方法

##### 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):
```

创建 Mosaic4 增强。

参数

 * `height` (`int | None`): 输出图像高度。
 * `width` (`int | None`): 输出图像宽度。
 * `image_fill_value` (`float | list[int] | list[float] | None`): 图像的填充值。
 * `mask_fill_value` (`float | list[int] | list[float] | None`): 掩码的填充值。
 * `p` (`float`): 应用变换的概率。
 * `out_height` (`int | None`):> **已弃用**
   > 自 0.9.0 版本起已弃用：请改用 `height`。
 * `out_width` (`int | None`):> **已弃用**
   > 自 0.9.0 版本起已弃用：请改用 `width`。
 * `value` (`float | list[int] | list[float] | None`):> **已弃用**
   > 自 0.9.0 版本起已弃用：请改用 `image_fill_value`。
 * `mask_value` (`float | list[int] | list[float] | None`):> **已弃用**
   > 自 0.9.0 版本起已弃用：请改用 `mask_fill_value`。

引发

 * `ValueError`: 如果解析的输出高度或宽度缺失或不大于 0。

##### apply

```python
def apply(image_batch: list[np.ndarray], x_crop: int, y_crop: int, **_) -> np.ndarray:
```

将马赛克增强应用于一批图像。

参数

 * `image_batch` (`list[np.ndarray]`): 要变换的图像。每张图像的形状应为 (H, W, C) 或 (H, W)。
 * `x_crop` (`int`): 裁剪起始点的 X 坐标。
 * `y_crop` (`int`): 裁剪起始点的 Y 坐标。
 * `**_`

返回

 * `np.ndarray`: 形状为 (Hout, Wout, C) 或 (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:
```

将马赛克增强应用于一批边界框。

参数

 * `bboxes_batch` (`list[np.ndarray]`): 要变换的边界框。
 * `image_shapes` (`list[tuple[int, int]]`): 原始图像形状。
 * `x_crop` (`int`): 裁剪起始点的 X 坐标。
 * `y_crop` (`int`): 裁剪起始点的 Y 坐标。
 * `**_`

返回

 * `np.ndarray`: 变换后的边界框。

##### apply_to_instance_mask

```python
def apply_to_instance_mask(masks_batch: list[np.ndarray], x_crop: int, y_crop: int, **_) -> np.ndarray:
```

将马赛克增强应用于一批实例分割掩码。

参数

 * `masks_batch` (`list[np.ndarray]`): 要变换的掩码。每个掩码的形状应为 (H, W, N)，其中 N 是实例数。
 * `x_crop` (`int`): 裁剪起始点的 X 坐标。
 * `y_crop` (`int`): 裁剪起始点的 Y 坐标。
 * `**_`

返回

 * `np.ndarray`: 形状为 (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:
```

将马赛克增强应用于一批关键点。

参数

 * `keypoints_batch` (`list[np.ndarray]`): 要变换的关键点。
 * `image_shapes` (`list[tuple[int, int]]`): 原始图像形状。
 * `x_crop` (`int`): 裁剪起始点的 X 坐标。
 * `y_crop` (`int`): 裁剪起始点的 Y 坐标。
 * `**_`

返回

 * `np.ndarray`: 变换后的关键点。

##### 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:
```

将马赛克增强应用于一批语义分割掩码。

参数

 * `mask_batch` (`list[np.ndarray]`): 要变换的掩码。每个掩码的形状应为 (H, W, C) 或 (H, W)。
 * `x_crop` (`int`): 裁剪起始点的 X 坐标。
 * `y_crop` (`int`): 裁剪起始点的 Y 坐标。
 * `out_height` (`int`): 输出掩码的预期高度。
 * `out_width` (`int`): 输出掩码的预期宽度。
 * `**_`

返回

 * `np.ndarray`: 形状为 (Hout, Wout, C) 或 (Hout, Wout) 的单个分割掩码。

##### generate_random_crop_center

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

在马赛克图像大小的边界内生成一个随机裁剪中心。

##### get_params_dependent_on_data

```python
def get_params_dependent_on_data(params: dict[str, Any], data: dict[str, Any]) -> dict[str, Any]:
```

获取依赖于目标的参数。

参数

 * `params` (`dict[str, Any]`): 现有增强参数。
 * `data` (`dict[str, Any]`): 输入数据。

返回

 * `dict[str, Any]`: 从输入目标派生的参数。
