Documentation Index
Fetch the complete documentation index at: https://docs.pixeltable.com/llms.txt
Use this file to discover all available pages before exploring further.
Problem
You need to fix inconsistent lighting across hundreds of images—adjusting brightness, contrast, and color saturation.Solution
What’s in this recipe:- Adjust brightness, contrast, and saturation
- Test adjustments before applying
- Process multiple images in batch
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.
For more on this workflow, see Get fast feedback on
transformations.
Setup
Load images
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘image_demo’.
<pixeltable.catalog.dir.Dir at 0x1441f2500>
Created table ‘enhancements’.
Inserting rows into `enhancements`: 0 rows [00:00, ? rows/s]Inserting rows into `enhancements`: 3 rows [00:00, 601.16 rows/s]
Inserted 3 rows with 0 errors.
3 rows inserted, 6 values computed.
Iterate: adjust brightness and contrast for a few images first
Add: adjust brightness and contrast for all images in your table
Added 3 column values with 0 errors.
Added 3 column values with 0 errors.
Added 3 column values with 0 errors.
Added 3 column values with 0 errors.
Added 3 column values with 0 errors.
Added 3 column values with 0 errors.
3 rows updated, 3 values computed.
View results
Compare different enhancement levels side-by-side.Explanation
How the enhancement technique works: The UDFs wrap PIL’sImageEnhance module to adjust visual properties of
images. Each enhancement type creates an enhancer object for the image,
then applies a multiplication factor. A factor of 1.0 leaves the image
unchanged, values below 1.0 decrease the property (darker, less
contrast, desaturated), and values above 1.0 increase it (brighter, more
contrast, saturated). You can apply different factors to the same image
to create multiple variations for comparison or different use cases.
To customize the UDFs:
- Brightness factors: Use 0.5 for darker images, 1.5 for brighter, or adjust to match your lighting needs
- Contrast factors: Use 0.5 for lower contrast, 2.0 for higher contrast, or fine-tune for image clarity
- Saturation factors: Use 0.3 for desaturated/muted colors, 2.0 for vibrant colors, or 0.0 for complete grayscale
- Combine adjustments: Apply multiple enhancements to create complex transformations
.select() just picks which columns to view.
In Pixeltable, .select() also lets you compute new transformations on
the fly—define new columns without storing them. This makes .select()
perfect for testing transformations before you commit them.
When you use .select(), you’re creating a query that doesn’t execute
until you call .collect(). You must use .collect() to execute the
query and return results—nothing is stored in your table. If you want to
collect only the first few rows, use .head(n) instead of .collect()
to test on a subset before processing your full dataset. Once satisfied,
use .add_computed_column() with the same expression to persist results
permanently.
For more on this workflow, see Get fast feedback on
transformations.