helios.data.functional¶
Functions¶
|
Load the given image using OpenCV. |
|
Load the given image using PIL. |
|
Convert the given tensor to a numpy array. |
|
Display the image held by the tensor. Useful for debugging purposes. |
|
Show batches of tensors. |
|
Change the order of the input image channels so the result is in (h, w, c) order. |
|
Return the Y (luma) channel of a YCbCr image. |
|
Convert the given numpy image array from BGR to YCBCR. |
|
Convert the given torch Tensor image array from RGB to YCBCR. |
Module Contents¶
- helios.data.functional.load_image(path: pathlib.Path, flags: int = cv2.IMREAD_COLOR, as_rgb: bool = True) numpy.typing.NDArray [source]¶
Load the given image using OpenCV.
flags
correspond to thecv2.IMREAD_
flags from OpenCV. Please see the full list of options here. If no value is passed, the image will be loaded usingcv2.IMREAD_COLOR
, which will load it as an 8-bit BGR image.as_rgb
can be used to automatically convert the image from OpenCV’s default BGR to RGB using the following logic: * If the image is grayscale, then it is returned as is. * If the image is a 3-channel BGR, it is converted to RGB. * If the image is a 4-channel BGRA, it is converted to RGBA. If all these checks fail, the image is returned as is.- Parameters:
path – the path to the image to load.
flags – the OpenCV flags to use when loading.
as_rgb – if true, the image will be converted from BGR/BGRA to RGB/RGBA, otherwise the image is returned as is.
- Returns:
The loaded image.
- helios.data.functional.load_image_pil(path: pathlib.Path, out_fmt: str = '', as_numpy: bool = True) numpy.typing.NDArray | PIL.Image.Image [source]¶
Load the given image using PIL.
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, setas_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 [source]¶
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 [source]¶
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 [source]¶
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 [source]¶
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 [source]¶
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 [source]¶
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 [source]¶
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.