The ML.CONVERT_COLOR_SPACE function

This document describes theML.CONVERT_COLOR_SPACE scalar function, which letsyou convert images that have anRGB color space to a different color space.You can useML.CONVERT_COLOR_SPACE with theML.PREDICTfunction orchain it with other functions or subqueries.

Syntax

ML.CONVERT_COLOR_SPACE(image, target_color_space)

Arguments

ML.CONVERT_COLOR_SPACE takes the following arguments:

  • image: aSTRUCT value that represents anRGB image in one of thefollowing 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 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).

    The struct value must be <= 60 MB.

  • target_color_space: aSTRING value that specifies the target color space.Valid values areHSV,GRAYSCALE,YIQ, andYUV.

Output

ML.CONVERT_COLOR_SPACE returns aSTRUCT value that represents themodified image in the formSTRUCT<ARRAY<INT64>, ARRAY<FLOAT64>>.

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. Each value in the second array is between[0, 1).

Note: If you referenceML.CONVERT_COLOR_SPACE 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.

Example

The following example uses theML.CONVERT_COLOR_SPACE function within theML.PREDICT function to change the color space for input images fromRGB toGRAYSCALE:

CREATEORREPLACETABLEmydataset.model_outputAS(SELECT*FROMML.PREDICT(MODEL`mydataset.mymodel`,SELECTML.CONVERT_COLOR_SPACE(ML.DECODE_IMAGE(data),'GRAYSCALE')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-12-15 UTC.