helios.data.functional

Functions

load_image(→ numpy.typing.NDArray | PIL.Image.Image)

Load the given image.

tensor_to_numpy(→ numpy.typing.NDArray)

Convert the given tensor to a numpy array.

show_tensor(→ None)

Display the image held by the tensor. Useful for debugging purposes.

show_tensors(→ None)

Show batches of tensors.

convert_to_hwc(→ numpy.typing.NDArray)

Change the order of the input image channels so the result is in (h, w, c) order.

to_y_channel(→ numpy.typing.NDArray)

Return the Y (luma) channel of a YCbCr image.

bgr2ycbcr(→ numpy.typing.NDArray)

Convert the given numpy image array from BGR to YCBCR.

rgb2ycbcr_torch(→ torch.Tensor)

Convert the given torch Tensor image array from RGB to YCBCR.

Module Contents

helios.data.functional.load_image(path: pathlib.Path, out_fmt: str = '', as_numpy: bool = True) numpy.typing.NDArray | PIL.Image.Image

Load the given image.

out_fmt is a format string that can be passed in to PIL.Image.convert. Please here for the list of accepted strings. If no string is passed, the image will be converted to RGB format. By default, the output is a NumPY array. If you need a PIL image instead, set as_numpy to false.

Parameters:
  • path – the path to the image to load.

  • out_fmt – the format to convert the loaded image to. Defaults to empty.

  • as_numpy – if true, the loaded image will be returned as a NumPY array, otherwise it is returned as a PIL image. Defaults to true.

Returns:

The loaded image.

helios.data.functional.tensor_to_numpy(tens: torch.Tensor, as_float: bool = False) numpy.typing.NDArray

Convert the given tensor to a numpy array.

Parameters:
  • tens – the tensor to convert in the range \([0, 1]\)

  • as_float – whether to leave the output as float or convert to int.

Returns:

The converted array.

helios.data.functional.show_tensor(tens: torch.Tensor, title: str = 'debug window') None

Display the image held by the tensor. Useful for debugging purposes.

Parameters:
  • tens – the image tensor to display in range \([0, 1]\).

  • title – the title of the displayed window. Defaults to “debug window”.

helios.data.functional.show_tensors(tens: torch.Tensor) None

Show batches of tensors.

Parameters:

tens – the batch of tensors to display in range \([0, 1]\).

helios.data.functional.convert_to_hwc(img: numpy.typing.NDArray, input_order: str = 'HWC') numpy.typing.NDArray

Change the order of the input image channels so the result is in (h, w, c) order.

If the input image is a single-channel image, then the return is (h, w, 1).

Parameters:
  • img – input image.

  • input_order – the order of the channels of the input image. Must be one of ‘HWC’ or ‘CHW’.

Returns:

The shuffled image.

helios.data.functional.to_y_channel(img: numpy.typing.NDArray) numpy.typing.NDArray

Return the Y (luma) channel of a YCbCr image.

Parameters:

img – input image in YCbCr format. Must be in the range \([0, 255]\).

Returns:

The luma channel of the input image.

helios.data.functional.bgr2ycbcr(img: numpy.typing.NDArray, only_y: bool = False) numpy.typing.NDArray

Convert the given numpy image array from BGR to YCBCR.

If only the Y channel is required, set only_y to true.

Parameters:
  • img – the BGR image to convert.

  • only_y – if true, only the luma (Y) channel will be returned.

Returns:

The converted image.

helios.data.functional.rgb2ycbcr_torch(img: torch.Tensor, only_y: bool = False) torch.Tensor

Convert the given torch Tensor image array from RGB to YCBCR.

If only the Y channel is required, set only_y to true.

Parameters:
  • img – the BGR image to convert.

  • only_y – if true, only the luma (Y) channel will be returned.

Returns:

The converted image.