The ML.RESIZE_IMAGE function

This document describes theML.RESIZE_IMAGE scalar function, which lets youresize images by usingbilinear interpolation.You can useML.RESIZE_IMAGE with theML.PREDICT functionor 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:

  • image: aSTRUCT value that represents an image, in one of the followingforms:

    • STRUCT<ARRAY<INT64>, ARRAY<FLOAT64>>
    • STRUCT<ARRAY<INT64>, ARRAY<INT64>>

    The first array in the struct must contain the dimensions of the image.It must contain threeINT64 values, which represent the image height (H),width (W), and number of channels (C).

    The second array in the struct must contain the image data. Thelength of the array must be equivalent to H x W x C from the precedingarray. If the image data is inFLOAT64, each value in the array must bebetween[0, 1). If the image data is inINT64, each value in the arraymust be between[0, 255).

    For example, a 1x2 image in theRGB color space might have a formsimilar to[[0.1,0.2,0.3],[0.4,0.5,0.6]], which would be representedas a struct in the form([1,2,3],[0.1,0.2,0.3,0.4,0.5,0.6]).

    The struct value must be <= 60 MB.

  • target_height: anINT64 value that specifies the height of the resizedimage in pixels, or the maximum acceptable height ifpreserve_aspect_ratiois set toTRUE.

  • target_width: anINT64 value that specifies the width of the resizedimage in pixels, or the maximum acceptable width ifpreserve_aspect_ratiois set toTRUE.

  • preserve_aspect_ratio: aBOOL value that indicates whetherthe existing height and width ratio of the image is preserved in theresized image. If set toTRUE, the function returns the largest possibleimage that falls within the specified height and width constraints butstill maintains the aspect ratio.

Output

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

The first array in the struct represents the dimensions of the image, andthe second array in the struct contains the image data, similarto theimage input argument.

Note: If you referenceML.RESIZE_IMAGE in SQL statements in theBigQuery editor, it is possible for the function output to betoo large to display. If this occurs, write the output to a table instead.

Examples

Example 1

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

CREATEORREPLACETABLE`mydataset.results`AS(SELECTuri,prediction_resultsFROMML.PREDICT(MODEL`mydataset.mymodel`,SELECTML.RESIZE_IMAGE(ML.DECODE_IMAGE(data),240,240,FALSE)ASimage,uriFROM`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).

CREATEORREPLACETABLE`mydataset.results`AS(SELECTuri,prediction_resultsFROMML.PREDICT(MODEL`mydataset.mymodel`,SELECTML.RESIZE_IMAGE(ML.DECODE_IMAGE(data),10,120,TRUE)ASimage,uriFROM`mydataset.images`));

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-24 UTC.