Skip to content

Image IO

Source

Functions relating reading and writing image files.

ReadFunc

Bases: Protocol

Protocol that defines the accepted function signature for "read functions".

Read functions take a file path and read image data into a numpy array.

The first argument MUST be named file_path and be type pathlib.Path, any number of additional arguments of any type are allowed. The return type MUST be numpy.typing.NDArray[Any]. For example:

def read_func_example(file_path: Path, extra_arg: int) -> NDArray[Any]: ...

__call__(file_path, *args, **kwargs)

Type hinted callables must match this function signature (not including self).

Parameters:

  • file_path (Path) –

    Path to file.

  • *args (Any, default: () ) –

    Other positional arguments.

  • **kwargs (Any, default: {} ) –

    Other keyword arguments.

WriteFunc

Bases: Protocol

Protocol for type hinting write functions.

__call__(file_path, img, *args, **kwargs)

Type hinted callables must match this function signature (not including self).

Parameters:

  • file_path (Path) –

    Path to file.

  • img (ndarray) –

    Image data to save.

  • *args

    Other positional arguments.

  • **kwargs

    Other keyword arguments.

get_read_func(data_type)

Get the read function for the data type.

Parameters:

Returns:

get_write_func(data_type)

Get the write function for the data type.

Parameters:

  • data_type ((tiff, custom), default: "tiff" ) –

    Data type.

Returns: