How to handle input images

In the workflow, the input images are stored in an Image object, which is specific to the workflows environment.

# Let's create a image_input object, of type Image, from a pil image
image_input = Image(image="image_name", source="path/../to/../image")

# Access the PIL image
image_input.image

# Access the raw bytes of the image
image_input.to_bytes

# Get the width and height of the image
image_input.width
image_input.height

# Save the image on disk
data = BytesIO()
self.image.save(data, format="JPEG", quality=95)

# Crop the image
image_input.get_crop(pred['bbox']) 

# Crop the image with a certain 10% extension factor
image_input.get_crop(pred['bbox'], extended=0.1)

# Resize an image
image_input.resize(scaling_factor=0.65, threshold=4)

# Rotate an image
image_input.rotate_image(rotation="rotation_180")

Please see with the product team if you need any other image manipulation method. For more custom needs you can also create a new class, that inherits from this one an add any necessary method.

Last updated