Skip to main content

ImageCrop

Crop the image to a specific x, y, width and height.

This module provides a pipeline element to crop the image to a specific x, y, width and height. This function is DESTRUCTIVE and will modify the image in place. It is not intended to be used after the any deep learning model or analytics has been applied. Please note that any image resizing needed for deep learning models are handled under-the-hood and the original image is preserved.

Examples:

REST API:

WIP

Configuration File:

short-from : image-crop:<i-x>:<i-y>:<i-w>:<i-h>, image-crop:<i-w>:<i-h>

Crop the 640x480 center of a 1920x1080 image:

source:
- address: https://youtu.be/jY86pXeTOLw
- type: youtube
pipeline:
- image-crop:960:540:640:480

ImageCrop Objects

class ImageCrop(Element)

Crop the image to a specific x, y, width and height.

Attributes:

  • name str - The name of the element.
  • x int - The x coordinate of the top left corner of the crop.
  • y int - The y coordinate of the top left corner of the crop.
  • width int - The width of the crop.
  • height int - The height of the crop.

Examples:

ele = ImageCrop(0, 0, 640, 480)

extract_params

@staticmethod
def extract_params(model_params)

Extract the parameters for this element.

Arguments:

  • model_params List[str] - The parameters for this element.

Returns:

  • x int - The x coordinate of the top left corner of the crop.
  • y int - The y coordinate of the top left corner of the crop.
  • width int - The width of the crop.
  • height int - The height of the crop.

Raises:

  • ExtractParameterException - If the parameters are not valid.

Examples:

params = ImageCrop.extract_params(["0", "0", "640", "480"])
ele = ImageCrop(*params)

process

def process(meta)

Process the metadata by cropping the image.

This is the main function for this element. It will process the metadata by cropping the image. This function is DESTRUCTIVE and will modify the image in place.

Arguments:

  • meta dict - The metadata to process.

Returns:

  • meta dict - The processed metadata.

Examples:

params = ImageCrop.extract_params(["0", "0", "640", "480"])
ele = ImageCrop(*params)
meta = ele.process(meta)