Stay organized with collections
Save and categorize content based on your preferences.
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.
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.
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:
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).
[[["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-25 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eML.RESIZE_IMAGE\u003c/code\u003e function resizes images using bilinear interpolation and can be used with the \u003ccode\u003eML.PREDICT\u003c/code\u003e function or chained with other functions/subqueries.\u003c/p\u003e\n"],["\u003cp\u003eIt accepts a \u003ccode\u003eSTRUCT\u003c/code\u003e representing the image, target height, target width, and a boolean to preserve the aspect ratio.\u003c/p\u003e\n"],["\u003cp\u003eThe image data within the \u003ccode\u003eSTRUCT\u003c/code\u003e can be represented by \u003ccode\u003eINT64\u003c/code\u003e values between \u003ccode\u003e[0, 255)\u003c/code\u003e or \u003ccode\u003eFLOAT64\u003c/code\u003e values between \u003ccode\u003e[0, 1)\u003c/code\u003e, and the dimensions are specified by height, width, and number of channels.\u003c/p\u003e\n"],["\u003cp\u003eWhen \u003ccode\u003epreserve_aspect_ratio\u003c/code\u003e is \u003ccode\u003eTRUE\u003c/code\u003e, the function returns the largest image possible within the target dimensions while maintaining the original aspect ratio.\u003c/p\u003e\n"],["\u003cp\u003eThe function outputs a \u003ccode\u003eSTRUCT\u003c/code\u003e value representing the resized image, mirroring the input format.\u003c/p\u003e\n"]]],[],null,["# The ML.RESIZE_IMAGE function\n============================\n\nThis document describes the `ML.RESIZE_IMAGE` scalar function, which lets you\nresize images by using\n[bilinear interpolation](https://en.wikipedia.org/wiki/Bilinear_interpolation).\nYou can use `ML.RESIZE_IMAGE` with the\n[`ML.PREDICT` function](/bigquery/docs/reference/standard-sql/bigqueryml-syntax-predict)\nor chain it with other functions or subqueries.\n\nSyntax\n------\n\n```sql\nML.RESIZE_IMAGE(image, target_height, target_width, preserve_aspect_ratio)\n```\n\n### Arguments\n\n`ML.RESIZE_IMAGE` takes the following arguments:\n\n- `image`: a `STRUCT` value that represents an image, in one of the following\n forms:\n\n - `STRUCT\u003cARRAY\u003cINT64\u003e, ARRAY\u003cFLOAT64\u003e\u003e`\n - `STRUCT\u003cARRAY\u003cINT64\u003e, ARRAY\u003cINT64\u003e\u003e`\n\n The first array in the struct must contain the dimensions of the image.\n It must contain three `INT64` values, which represent the image height (H),\n width (W), and number of channels (C).\n\n The second array in the struct must contain the image data. The\n length of the array must be equivalent to H x W x C from the preceding\n array. If the image data is in `FLOAT64`, each value in the array must be\n between `[0, 1)`. If the image data is in `INT64`, each value in the array\n must be between `[0, 255)`.\n\n For example, a 1x2 image in the `RGB` color space might have a form\n similar to `[[0.1,0.2,0.3],[0.4,0.5,0.6]]`, which would be represented\n as a struct in the form `([1,2,3],[0.1,0.2,0.3,0.4,0.5,0.6])`.\n\n The struct value must be \\\u003c= 60 MB.\n- `target_height`: an `INT64` value that specifies the height of the resized\n image in pixels, or the maximum acceptable height if `preserve_aspect_ratio`\n is set to `TRUE`.\n\n- `target_width`: an `INT64` value that specifies the width of the resized\n image in pixels, or the maximum acceptable width if `preserve_aspect_ratio`\n is set to `TRUE`.\n\n- `preserve_aspect_ratio`: a `BOOL` value that indicates whether\n the existing height and width ratio of the image is preserved in the\n resized image. If set to `TRUE`, the function returns the largest possible\n image that falls within the specified height and width constraints but\n still maintains the aspect ratio.\n\nOutput\n------\n\n`ML.RESIZE_IMAGE` returns a `STRUCT` value that represents the resized image,\nwith the same form as the `image` input argument.\n\nThe first array in the struct represents the dimensions of the image, and\nthe second array in the struct contains the image data, similar\nto the `image` input argument.\n| **Note:** If you reference `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.\n\nExamples\n--------\n\n**Example 1**\n\nThe following example resizes input images to have a height and width\nof 240 pixels: \n\n```sql\nCREATE OR REPLACE TABLE `mydataset.results`\nAS (\n SELECT uri, prediction_results\n FROM\n ML.PREDICT(\n MODEL `mydataset.mymodel`,\n SELECT\n ML.RESIZE_IMAGE(ML.DECODE_IMAGE(data), 240, 240, FALSE)\n AS image,\n uri\n FROM `mydataset.images`)\n);\n```\n\n**Example 2**\n\nThe following example resizes input images while preserving the aspect ratio.\nWith the settings shown, the function returns an image with dimensions of\n`(10, 100)` for an input image with dimensions of `(20, 200)`. \n\n```sql\nCREATE OR REPLACE TABLE `mydataset.results`\nAS (\n SELECT uri, prediction_results\n FROM\n ML.PREDICT(\n MODEL `mydataset.mymodel`,\n SELECT\n ML.RESIZE_IMAGE(ML.DECODE_IMAGE(data), 10, 120, TRUE)\n AS image,\n uri\n FROM `mydataset.images`)\n);\n```\n\nWhat's next\n-----------\n\n- For information about feature preprocessing, see [Feature preprocessing overview](/bigquery/docs/preprocess-overview).\n- For information about the supported SQL statements and functions for each model type, see [End-to-end user journey for each model](/bigquery/docs/e2e-journey)."]]