Convert color images to grayscale

You need to convert color images to grayscale for analysis, preprocessing, or model inputs that require single-channel images.

Images · Notebook · Updated

Colab runs it in your browser. If it calls a model provider, it asks for that provider's API key in a cell.

How it works

You convert RGB images to grayscale in your table using either Pixeltable's built-in .convert() method for standard conversion, or a custom UDF (relies on NumPy and PIL/Pillow) for gamma-corrected conversion when scientific accuracy matters.

You can iterate on transformations before adding them to your table. Use .select() with .collect() to preview results on sample images—nothing is stored in your table. If you want to collect only the first few rows, use .head(n) instead of .collect(). Once you're satisfied, use .add_computed_column() to apply the conversion to all images in your table.

What it covers

  • Simple conversion with PIL
  • Perceptually accurate grayscale (weighted RGB channels)
  • Custom UDF for advanced conversion

What it uses

Install
terminal
pip install pixeltable numpy
Pixeltable calls
pxt.create_table()@pxt.udfinsert()add_computed_column()
Browse all 103