Stay organized with collections Save and categorize content based on your preferences.
The ML.RESIZE_IMAGE functionThis 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.
ML.RESIZE_IMAGE(image, target_height, target_width, preserve_aspect_ratio)Arguments
ML.RESIZE_IMAGE
takes the following arguments:
image
: a STRUCT
value that represents an image, in one of the following forms:
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 three INT64
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. The length of the array must be equivalent to H x W x C from the preceding array. If the image data is in FLOAT64
, each value in the array must be between [0, 1)
. If the image data is in INT64
, each value in the array must be between [0, 255)
.
For example, a 1x2 image in the RGB
color space might have a form similar to [[0.1,0.2,0.3],[0.4,0.5,0.6]]
, which would be represented as 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
: an INT64
value that specifies the height of the resized image in pixels, or the maximum acceptable height if preserve_aspect_ratio
is set to TRUE
.
target_width
: an INT64
value that specifies the width of the resized image in pixels, or the maximum acceptable width if preserve_aspect_ratio
is set to TRUE
.
preserve_aspect_ratio
: a BOOL
value that indicates whether the existing height and width ratio of the image is preserved in the resized image. If set to TRUE
, the function returns the largest possible image that falls within the specified height and width constraints but still maintains the aspect ratio.
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.
ML.RESIZE_IMAGE
in SQL statements in the BigQuery editor, it is possible for the function output to be too 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 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
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["The `ML.RESIZE_IMAGE` function resizes images using bilinear interpolation and can be used with the `ML.PREDICT` function or chained with other functions/subqueries."],["It accepts a `STRUCT` representing the image, target height, target width, and a boolean to preserve the aspect ratio."],["The image data within the `STRUCT` can be represented by `INT64` values between `[0, 255)` or `FLOAT64` values between `[0, 1)`, and the dimensions are specified by height, width, and number of channels."],["When `preserve_aspect_ratio` is `TRUE`, the function returns the largest image possible within the target dimensions while maintaining the original aspect ratio."],["The function outputs a `STRUCT` value representing the resized image, mirroring the input format."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4