hezar.utils.image_utils module¶
- hezar.utils.image_utils.convert_image_type(image: np.ndarray | 'Image' | torch.Tensor, target_type: str | ImageType = ImageType.NUMPY)[source]¶
Convert image lib type. Supports numpy array, pillow image and torch tensor.
- hezar.utils.image_utils.find_channels_axis_side(image: ndarray, num_channels: int | None = None)[source]¶
- hezar.utils.image_utils.gray_scale_image(image: np.ndarray, return_type: str | ImageType = ImageType.NUMPY)[source]¶
- hezar.utils.image_utils.load_image(path, return_type: str | ImageType = ImageType.PILLOW)[source]¶
Load an image file to a desired return format
- Parameters:
path – Path to image file
return_type – Image output type (“pillow”, “numpy”, “torch”)
- Returns:
The desired output image of type PIL.Image or numpy.ndarray or torch.Tensor
- hezar.utils.image_utils.mirror_image(image: np.ndarray, return_type: str | ImageType = ImageType.NUMPY)[source]¶
- hezar.utils.image_utils.normalize_image(image: np.ndarray, mean: float | Iterable[float], std: float | Iterable[float], channel_axis: str | ChannelsAxisSide = 'first')[source]¶
- hezar.utils.image_utils.resize_image(image: ndarray, size: Tuple[int, int], resample=None, reducing_gap: float | None = None, return_type: ImageType = ImageType.NUMPY)[source]¶
Resize a numpy array image (actually uses pillow PIL.Image.resize(…))
- Parameters:
image – Numpy image
size – A tuple of (width, height)
resample – Resampling filter (refer to PIL.Image.Resampling) for possible values
reducing_gap – Optimization method for resizing based on reducing times
return_type – Return type of the image (numpy, torch, pillow)
- Returns:
The resized image
- hezar.utils.image_utils.show_image(image: 'Image' | torch.Tensor | np.ndarray, title: str = 'Image')[source]¶
Given any type of input image (PIL, numpy, torch), show the image in a window
- Parameters:
image – Input image of types PIL.Image, numpy.ndarray or torch.Tensor
title – Optional title for the preview window
- hezar.utils.image_utils.transpose_channels_axis_side(image: np.ndarray, axis_side: str | ChannelsAxisSide, num_channels: int = None, src_axis_side: str | ChannelsAxisSide = None)[source]¶
Convert an image channels axis side from (channels, …) to (…, channels) or vise versa.
- Parameters:
image – Input image
axis_side – The desired axis side (can be “first” or “last”)
num_channels – The number of channels in the input image
src_axis_side – The image initial channels axis side (can be “first” or “last”)
- Returns:
The image with the converted channels axis