🖼 ️image module¶
Performs multiple operations over images, like resizing,loading and so on
- class pupyl.duplex.image.ImageIO¶
Operations of read and write over images.
- classmethod compress(tensor, as_tensor=False)¶
Compress the tensor using the JPEG algorithm.
- Parameters:
tensor (
numpy.ndarray) – A tensor representing an imageas_tensor (
bool) – If the new compressed JPEG image should be returned as anumpy.ndarray.
- Returns:
An encoded image, in bytes or a tensor in numpy.ndarray
- Return type:
bytesornumpy.ndarray
- static encoded_to_compressed_tensor(encoded)¶
Transforms a binary encoded string image to its compressed tensor form.
- Parameters:
encoded (
bytes) – The binary representation of the image.- Returns:
The actual compressed image tensor.
- Return type:
numpy.ndarray
- static encoded_to_tensor(encoded)¶
Transforms a binary encoded string image to a tensor.
- Parameters:
encoded (
bytes) – The binary representation of the image.- Returns:
Describing the compressed image tensor.
- Return type:
numpy.ndarray
- classmethod get_image(uri, as_tensor=False)¶
Loads an image from a specified location.
- Parameters:
uri (
str) – Location where the image are stored.as_tensor (
bool) – If the image should be converted to its tensor representation. Defaults to False, which returns images to a byte representation
- Returns:
Respectively returns the image as bytes or as a tensor representation.
- Return type:
bytesornumpy.ndarray
- classmethod get_image_base64(uri)¶
Loads an image as a base64 encoded string.
- Parameters:
uri (
str) – Location where the image is stored.- Returns:
The base64 encoded image format.
- Return type:
bytes
- classmethod get_image_bytes_to_base64(image_bytes)¶
Returns the image representation in base64, from its bytes representation.
- Parameters:
image_bytes (
bytes) – Bytes representation of some image.- Raises:
FileIsNotImage: – If the file is not recognized as an image.
- Returns:
The base64 encoded image format.
- Return type:
bytes
- classmethod is_animated_gif(uri)¶
Tests if the content is an animated GIF image.
- Parameters:
uri (
str) – Place where the animated GIF is stored.- Returns:
Describing if
tensorrepresents a GIF animation or not.- Return type:
bool
- classmethod mean_gif(uri)¶
Transforms an animated GIF to an static representation (based on the mean image).
- Parameters:
uri (
str) – Place where the animated GIF is stored.- Returns:
A new representation for the GIF (animated) image.
- Return type:
numpy.ndarray
- static resize_tensor(tensor, size, keep_aspect=False)¶
Resize a tensor representing an image.
- Parameters:
tensor (
numpy.ndarray) – An image transformed to a raw tensor.size (
tupleofints) – The new size.
- Returns:
A resized tensor based on
sizeparameter.- Return type:
numpy.ndarray
- static save_image(path, bytess)¶
Saves an image to a defined path.
- Parameters:
path (
str) – Local to save the image.bytess (
bytes) – Bytes representing an image.
- scan_images(uri)¶
Scans a source looking for images.
- Parameters:
uri (
str) – Location where the source is stored.- Yields:
str– The validated image file on the passeduri.
- classmethod size(uri, new_size=None, keep_aspect=False)¶
Returns the current image dimensions or resize it.
- Parameters:
uri (
str) – Description of where the image are located.new_size (
tupleofints) – The new intended dimension of the image.keep_aspect (
bool) – If the image proportions should be preserved. or not.
- Returns:
Respectively with current image dimensions or if new_size is
True, a resized image, ifnew_sizeparameter was passed through.- Return type:
tupleornumpy.ndarray