datumaro.util.image#

Module Attributes

ImageMeta

filename -> height, width

Functions

copyto_image(src, dst, src_crypter, dst_crypter)

decode_image(image_bytes[, dtype])

encode_image(image, ext[, dtype])

find_images(dirpath[, exts, recursive, ...])

is_image(path)

load_image(path[, dtype, crypter])

Reads an image in the HWC Grayscale/BGR(A) [0; 255] format (default dtype is uint8).

load_image_meta_file(image_meta_path)

Loads image metadata from a file with the following format:

save_image(dst, image[, ext, create_dir, ...])

save_image_meta_file(image_meta, image_meta_path)

Saves image_meta to the path specified by image_meta_path in the format defined in load_image_meta_file's documentation.

Classes

lazy_image(path, loader, ...)

Cache:

datumaro.util.image.load_image(path: str, dtype: ~typing.Union[~numpy.dtype[~typing.Any], None, type[typing.Any], ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]], str, tuple[typing.Any, int], tuple[typing.Any, typing.Union[typing.SupportsIndex, collections.abc.Sequence[typing.SupportsIndex]]], list[typing.Any], ~numpy._typing._dtype_like._DTypeDict, tuple[typing.Any, typing.Any]] = <class 'numpy.uint8'>, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#

Reads an image in the HWC Grayscale/BGR(A) [0; 255] format (default dtype is uint8).

datumaro.util.image.copyto_image(src: Union[str, IOBase], dst: Union[str, IOBase], src_crypter: Crypter, dst_crypter: Crypter) None[source]#
datumaro.util.image.save_image(dst: ~typing.Union[str, ~io.IOBase], image: ~numpy.ndarray, ext: ~typing.Optional[str] = None, create_dir: bool = False, dtype: ~typing.Union[~numpy.dtype[~typing.Any], None, type[typing.Any], ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]], str, tuple[typing.Any, int], tuple[typing.Any, typing.Union[typing.SupportsIndex, collections.abc.Sequence[typing.SupportsIndex]]], list[typing.Any], ~numpy._typing._dtype_like._DTypeDict, tuple[typing.Any, typing.Any]] = <class 'numpy.uint8'>, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>, **kwargs) None[source]#
datumaro.util.image.encode_image(image: ~numpy.ndarray, ext: str, dtype: ~typing.Union[~numpy.dtype[~typing.Any], None, type[typing.Any], ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]], str, tuple[typing.Any, int], tuple[typing.Any, typing.Union[typing.SupportsIndex, collections.abc.Sequence[typing.SupportsIndex]]], list[typing.Any], ~numpy._typing._dtype_like._DTypeDict, tuple[typing.Any, typing.Any]] = <class 'numpy.uint8'>, **kwargs) bytes[source]#
datumaro.util.image.decode_image(image_bytes: bytes, dtype: ~typing.Union[~numpy.dtype[~typing.Any], None, type[typing.Any], ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]], str, tuple[typing.Any, int], tuple[typing.Any, typing.Union[typing.SupportsIndex, collections.abc.Sequence[typing.SupportsIndex]]], list[typing.Any], ~numpy._typing._dtype_like._DTypeDict, tuple[typing.Any, typing.Any]] = <class 'numpy.uint8'>) ndarray[source]#
datumaro.util.image.find_images(dirpath: str, exts: Optional[Union[str, Iterable[str]]] = None, recursive: bool = False, max_depth: Optional[int] = None, min_depth: Optional[int] = None) Iterator[str][source]#
datumaro.util.image.is_image(path: str) bool[source]#
class datumaro.util.image.lazy_image(path: str, loader: ~typing.Optional[~typing.Callable[[str], ~numpy.ndarray]] = None, cache: ~typing.Union[bool, ~datumaro.util.image_cache.ImageCache] = True, crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>)[source]#

Bases: object

Cache:
  • False: do not cache

  • True: use the global cache

  • ImageCache instance: an object to be used as cache

datumaro.util.image.ImageMeta#

filename -> height, width

alias of Dict[str, Tuple[int, int]]

datumaro.util.image.load_image_meta_file(image_meta_path: str) Dict[str, Tuple[int, int]][source]#

Loads image metadata from a file with the following format:

<image name 1> <height 1> <width 1>

<image name 2> <height 2> <width 2>

Shell-like comments and quoted fields are allowed.

This can be useful to support datasets in which image dimensions are required to interpret annotations.

datumaro.util.image.save_image_meta_file(image_meta: Dict[str, Tuple[int, int]], image_meta_path: str) None[source]#

Saves image_meta to the path specified by image_meta_path in the format defined in load_image_meta_file’s documentation.