The ML.RESIZE_IMAGE function

This document describes the ML.RESIZE_IMAGE scalar function, which lets you resize images by using bilinear interpolation. You can use ML.RESIZE_IMAGE with the ML.PREDICT function or chain it with other functions or subqueries.

Syntax

ML.RESIZE_IMAGE(image, target_height, target_width, preserve_aspect_ratio)

Arguments

ML.RESIZE_IMAGE takes the following arguments:

Output

ML.RESIZE_IMAGE returns a STRUCT value that represents the resized image, with the same form as the image input argument.

The first array in the struct represents the dimensions of the image, and the second array in the struct contains the image data, similar to the image input argument.

Examples

Example 1

The following example resizes input images to have a height and width of 240 pixels:

CREATE OR REPLACE TABLE `mydataset.results`
AS (
  SELECT uri, prediction_results
  FROM
    ML.PREDICT(
      MODEL `mydataset.mymodel`,
      SELECT
        ML.RESIZE_IMAGE(ML.DECODE_IMAGE(data), 240, 240, FALSE)
        AS image,
        uri
      FROM `mydataset.images`)
);

Example 2

The following example resizes input images while preserving the aspect ratio. With the settings shown, the function returns an image with dimensions of (10, 100) for an input image with dimensions of (20, 200).

CREATE OR REPLACE TABLE `mydataset.results`
AS (
  SELECT uri, prediction_results
  FROM
    ML.PREDICT(
      MODEL `mydataset.mymodel`,
      SELECT
        ML.RESIZE_IMAGE(ML.DECODE_IMAGE(data), 10, 120, TRUE)
        AS image,
        uri
      FROM `mydataset.images`)
);

What's next