Adjust image brightness and contrast

You need to fix inconsistent lighting across hundreds of images—adjusting brightness, contrast, and color saturation.

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 adjust brightness, contrast, and saturation for images in your table using custom UDFs that wrap Pillow's ImageEnhance module (relies on PIL/Pillow). This lets you control enhancement levels to match your needs.

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 adjustments to all images in your table.

What it covers

  • Adjust brightness, contrast, and saturation
  • Test adjustments before applying
  • Process multiple images in batch

What it uses

Install
terminal
pip install pixeltable
Pixeltable calls
pxt.create_table()@pxt.udfinsert()add_computed_column()

A look at the code

img-brightness-contrast.ipynb
# Brightness adjustments (1.0 = original)
t.add_computed_column(darker=adjust_brightness(t.image, 0.5))
t.add_computed_column(brighter=adjust_brightness(t.image, 1.5))
# Contrast adjustments
t.add_computed_column(low_contrast=adjust_contrast(t.image, 0.5))
t.add_computed_column(high_contrast=adjust_contrast(t.image, 2.0))
# Color saturation
t.add_computed_column(desaturated=adjust_saturation(t.image, 0.3))
t.add_computed_column(saturated=adjust_saturation(t.image, 2.0))

One cell of the notebook, copied as it is. Open it in Colab for the rest.

Browse all 103