# image

Python API: `modelconverter.utils.image`

Loading of calibration and inference input data.

Calibration data is provided as a directory of images or of raw arrays. This module finds those files and turns a single one of
them into the array shape, color encoding and data type that the exporters and inferers of the individual platforms feed to their
models.

## Functions

| Name | Description |
| --- | --- |
| [`read_calib_dir`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/image.md#image-Functions-read_calib_dir) | Collect the calibration files in a directory. |
| [`read_image`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/image.md#image-Functions-read_image) | Read a single calibration or inference input from a file. |

### function `read_calib_dir`

```python
def read_calib_dir(path: Path) -> list[Path]
```

Collect the calibration files in a directory.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `path` | `Path` | Directory to search. It is not searched recursively. | required |

Returns

| Type | Description |
| --- | --- |
| `list[Path]` | Paths of the `.jpg`, `.png`, `.jpeg`, `.npy`, and `.raw` files in the directory. |

### function `read_image`

```python
def read_image(
    path: PathType,
    shape: list[int],
    encoding: Encoding,
    resize_method: ResizeMethod,
    *,
    data_type: DataType | None = None,
    transpose: bool = True,
    layout: str | None = None,
) -> npt.NDArray[np.generic]
```

Read a single calibration or inference input from a file.

`.npy` files are loaded as they are and `.raw` files are read as a flat buffer of `data_type` reshaped to `shape`. Any other file
is opened as an image, converted to `encoding`, and fitted to the height and width taken from `shape`.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `path` | `PathType` | Path of the file to read. | required |
| `shape` | `list[int]` | Shape of the model input the file is read for. | required |
| `encoding` | `Encoding` | Color encoding the image is converted to. Ignored for `.npy` and `.raw` files. | required |
| `resize_method` | `ResizeMethod` | How the image is fitted to the requested height and width. Ignored for `.npy` and `.raw` files. | required |
| `data_type` | `DataType | None` | Data type the resulting array is cast to. Images are cast to `uint8` if it is `None`. Required for `.raw` files and ignored for `.npy` files. | `None` |
| `transpose` | `bool` | If `True`, the image is transposed from `HWC` to `CHW`. Ignored for `.npy` and `.raw` files. | `True` |
| `layout` | `str | None` | Lettercode layout of `shape`, used to find the `H`, `W`, and `C` axes. If it is `None`, its length does not match `shape`, or it lacks `H` or `W`, the axes are guessed from the number of dimensions. | `None` |

Returns

| Type | Description |
| --- | --- |
| `npt.NDArray[np.generic]` | The loaded data as a `numpy.ndarray`. |

Raises

| Type | Description |
| --- | --- |
| `ModelconverterException` | If a `.raw` file is read without `data_type`, or if `shape` has a length that cannot be interpreted as an image. |
