paidiverpy.open_layer.utils#

Open Layer utils module.

Functions#

open_image_remote(→ tuple[numpy.ndarray[Any, ...)

Open an image file.

open_image_local(→ tuple[numpy.ndarray[Any, ...)

Open an image file.

correct_image_dims_and_format(→ numpy.ndarray[Any, ...)

Correct the image dimensions and format.

pad_image(→ numpy.ndarray[Any, ...)

Pad the image to the target height and width.

load_raw_image(→ numpy.ndarray[Any, ...)

Load a raw image file.

load_raw_image_using_path_open(→ numpy.ndarray[Any, ...)

Load a raw image file using the open function.

decode_8bpp(→ numpy.ndarray[Any, Any])

Decode 8-bit per channel image data.

decode_16bpp(→ numpy.ndarray[Any, Any])

Decode 16-bit packed RGB into 8-bit per channel RGB based on layout.

extract_exif_single(→ dict[str, Any])

Extract EXIF data from a single image file.

Module Contents#

paidiverpy.open_layer.utils.open_image_remote(img_path: str, image_type: str, image_open_args: dict[str, Any], **kwargs: dict[str, Any]) tuple[numpy.ndarray[Any, Any] | dask.array.core.Array, dict[str, Any], str][source]#

Open an image file.

Parameters:
  • img_path (str) – The path to the image file

  • image_type (str) – The image type

  • image_open_args (dict[str, Any]) – The image open arguments

  • **kwargs (dict[str, Any]) – Additional keyword arguments. The following are supported: - storage_options (dict[str, Any]): The storage options for reading metadata file.

Raises:

ValueError – Failed to open the image

Returns:

The image data, the EXIF data, and the filename

Return type:

tuple[np.ndarray[Any, Any] | da.core.Array, dict[str, Any], str]

paidiverpy.open_layer.utils.open_image_local(img_path: str, image_type: str, image_open_args: dict[str, Any], **_kwargs: dict[str, Any]) tuple[numpy.ndarray[Any, Any] | dask.array.core.Array, dict[str, Any], str][source]#

Open an image file.

Parameters:
  • img_path (str) – The path to the image file

  • image_type (str) – The image type

  • image_open_args (dict) – The image open arguments

  • **_kwargs (dict) – Additional keyword arguments. This is just a place holder for the code

Raises:

ValueError – Failed to open the image

Returns:

The image data, the EXIF data, and the filename

Return type:

tuple[np.ndarray[Any, Any] | da.core.Array, dict, str]

paidiverpy.open_layer.utils.correct_image_dims_and_format(img: numpy.ndarray[Any, Any] | dask.array.core.Array, image_type: str | None = None) numpy.ndarray[Any, Any] | dask.array.core.Array[source]#

Correct the image dimensions and format.

Parameters:
  • img (np.ndarray[Any, Any] | da.core.Array) – The image data

  • image_type (str | None) – The image type

Returns:

The corrected image data

Return type:

np.ndarray[Any, Any] | da.core.Array

paidiverpy.open_layer.utils.pad_image(img: numpy.ndarray[Any, Any] | dask.array.core.Array, target_height: int, target_width: int) numpy.ndarray[Any, Any] | dask.array.core.Array[source]#

Pad the image to the target height and width.

Parameters:
  • img (np.ndarray[Any, Any] | da.core.Array) – The image data

  • target_height (int) – The target height

  • target_width (int) – The target width

Returns:

The padded image

Return type:

np.ndarray[Any, Any] | da.core.Array

paidiverpy.open_layer.utils.load_raw_image(img_path: str | io.BytesIO, image_type: str, image_open_args: dict[str, Any], remote: bool = False) numpy.ndarray[Any, Any] | dask.array.core.Array[source]#

Load a raw image file.

Parameters:
  • img_path (str | BytesIO) – The path to the image file or a BytesIO object

  • image_type (str | None) – The image type

  • image_open_args (dict | None) – The image open arguments

  • remote (bool) – Whether the image is remote or local. Defaults to False.

Raises:

ValueError – Failed to open the image

Returns:

The loaded image data

Return type:

np.ndarray[Any, Any]

paidiverpy.open_layer.utils.load_raw_image_using_path_open(img_path: str | io.BytesIO, image_open_args: dict[str, Any], remote: bool = False) numpy.ndarray[Any, Any] | dask.array.core.Array[source]#

Load a raw image file using the open function.

Parameters:
  • img_path (str) – The path to the image file or a BytesIO object

  • image_open_args (dict | None) – The image open arguments

  • remote (bool) – Whether the image is remote or local. Defaults to False.

Raises:

ValueError – Failed to open the image

Returns:

The loaded image data

Return type:

np.ndarray[Any, Any]

paidiverpy.open_layer.utils.decode_8bpp(img: numpy.ndarray[Any, Any], image_misc: list[str], width: int, height: int, channels: int, bayer_pattern: str | None = None) numpy.ndarray[Any, Any][source]#

Decode 8-bit per channel image data.

Parameters:
  • img (np.ndarray[Any, Any]) – The image data.

  • image_misc (list[str]) – The image metadata.

  • width (int) – The width of the image.

  • height (int) – The height of the image.

  • channels (int) – The number of channels in the image.

  • bayer_pattern (str | None) – The Bayer pattern if the image is in Bayer format. Defaults to None.

Returns:

The decoded image data.

Return type:

np.ndarray[Any, Any]

paidiverpy.open_layer.utils.decode_16bpp(img: numpy.ndarray[Any, Any], layout: str = '5:6:5', width: int = 2448, height: int = 2048, endianess: str | None = None) numpy.ndarray[Any, Any][source]#

Decode 16-bit packed RGB into 8-bit per channel RGB based on layout.

Parameters:
  • img (np.ndarray[Any, Any]) – The packed 16-bit image data.

  • layout (str) – The layout of the packed data. Valid options include “5:6:5”, “5:5:5”, “5:5:6”.

  • width (int) – The width of the image.

  • height (int) – The height of the image.

  • endianess (bool) – Whether to swap the byte order.

Returns:

The unpacked 8-bit RGB image data.

Return type:

np.ndarray[Any, Any]

paidiverpy.open_layer.utils.extract_exif_single(img_path: str | io.BytesIO, image_type: str, image_name: str | None = None) dict[str, Any][source]#

Extract EXIF data from a single image file.

Parameters:
  • img_path (str | BytesIO) – The path to the image file or a BytesIO object.

  • image_type (str) – The image type.

  • image_name (str, optional) – The name of the image file. Defaults to None.

Returns:

The EXIF data.

Return type:

dict