Skip to main content

ImageResize

Resize the image to either a specific shape or scale.

This module provides a pipeline element to resize the image to a specific shape or scale it and preserve the aspect ratio. This function is DESTRUCTIVE and will modify the image in place. 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-resize:<i-w>:<i-h>, image-resize:<f-scale>

Scale an image to 640x480:

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

Scale down an image by 50%:

source:
- address: https://youtu.be/jY86pXeTOLw
- type: youtube
pipeline:
- image-resize:0.5

ImageResize Objects

class ImageResize(Element)

Resize the image to either a specific shape or scale it and preserve the aspect ratio.

Attributes:

  • name str - The name of the element.
  • width int - The width of the resized image.
  • height int - The height of the resized image.
  • scale float - The scale to target.

Examples:

Shape:

ele = ImageResize(640, 480)

Scale:

ele = ImageResize(scale=0.5)

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:

  • width int - The width of the resized image.
  • height int - The height of the resized image.
  • scale float - The scale to target.

Raises:

  • ExtractParameterException - If the parameters are not valid.

Examples:

Shape:

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

Scale:

params = ImageResize.extract_params(["0.5"])
ele = ImageResize(*params)

process

 | @parallel
| def process(meta)

Process the metadata by resizing the image.

This is the main function for this element. It will process the metadata by resizing 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 = ImageResize.extract_params(["640", "480"])
ele = ImageResize(*params)
meta = ele.process(meta)