---
title: "Convert color images to grayscale"
description: "You need to convert color images to grayscale for analysis, preprocessing, or model inputs that require single-channel images."
url: "https://www.pixeltable.com/notebooks/img-rgb-to-grayscale"
updated: "2026-04-10"
---

# Convert color images to grayscale

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

- **Type:** Notebook
- **Group:** Images

## 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:** `pip install pixeltable numpy`
- **Pixeltable calls:** `pxt.create_table()`, `@pxt.udf`, `insert()`, `add_computed_column()`

## Open it

- **Open in Colab:** https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/images/img-rgb-to-grayscale.ipynb
- **Docs page:** https://docs.pixeltable.com/howto/cookbooks/images/img-rgb-to-grayscale
- **Source on GitHub:** https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/images/img-rgb-to-grayscale.ipynb
