The ML.CONVERT_COLOR_SPACE function

This document describes the ML.CONVERT_COLOR_SPACE scalar function, which lets you convert images that have an RGB color space to a different color space. You can use ML.CONVERT_COLOR_SPACE with the ML.PREDICT function or chain it with other functions or subqueries.

Syntax

ML.CONVERT_COLOR_SPACE(image, target_color_space)

Arguments

ML.CONVERT_COLOR_SPACE takes the following arguments:

Output

ML.CONVERT_COLOR_SPACE returns a STRUCT value that represents the modified image in the form STRUCT<ARRAY<INT64>, ARRAY<FLOAT64>>.

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

Example

The following example uses the ML.CONVERT_COLOR_SPACE function within the ML.PREDICT function to change the color space for input images from RGB to GRAYSCALE:

CREATE OR REPLACE TABLE mydataset.model_output
AS (
  SELECT *
  FROM
    ML.PREDICT(
      MODEL `mydataset.mymodel`,
      SELECT
        ML.CONVERT_COLOR_SPACE(ML.DECODE_IMAGE(data), 'GRAYSCALE')
          AS image,
        uri
      FROM `mydataset.images`)
);

What's next