imgutils.data.image

load_image

imgutils.data.image.load_image(image: str | PathLike | bytes | bytearray | BinaryIO | Image, mode=None, force_background: str | None = 'white')[source]

Loads the image from the provided source and applies necessary transformations.

The function supports loading images from various sources, such as file paths, binary data, or file-like objects. It opens the image using the PIL library and converts it to the specified mode if required. If the image has an RGBA (4-channel) format and a force_background value is provided, a background of the specified color will be added to avoid data anomalies during subsequent conversion processes.

Parameters:
  • image (Union[str, PathLike, bytes, bytearray, BinaryIO, Image.Image]) – The source of the image to be loaded.

  • mode (str or None) – The mode to convert the image to. If None, the original mode will be retained. (default: None)

  • force_background (str or None) – The color of the background to be added for RGBA images. If None, no background will be added. (default: white)

Returns:

The loaded and transformed image.

Return type:

Image.Image

load_images

imgutils.data.image.load_images(images: str | PathLike | bytes | bytearray | BinaryIO | Image | List[str | PathLike | bytes | bytearray | BinaryIO | Image] | Tuple[str | PathLike | bytes | bytearray | BinaryIO | Image, ...], mode=None, force_background: str | None = 'white') List[Image][source]

Loads a list of images from the provided sources and applies necessary transformations.

The function takes a single image or a list/tuple of multiple images and calls load_image() function on each item to load and transform the images. The images are returned as a list of PIL Image objects.

Parameters:
  • images (MultiImagesTyping) – The sources of the images to be loaded.

  • mode (str or None) – The mode to convert the images to. If None, the original modes will be retained. (default: None)

  • force_background (str or None) – The color of the background to be added for RGBA images. If None, no background will be added. (default: white)

Returns:

A list of loaded and transformed images.

Return type:

List[Image.Image]