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 apply filters to hundreds of images—blur, sharpen, edge detection, and other enhancements.Solution
What’s in this recipe:- Apply common image filters
- Test filters before applying
- Process multiple images in batch
ImageFilter module
(relies on PIL/Pillow). This gives you control over filter parameters.
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 filter 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 0x15bb85a50>
Created table ‘filters’.
Inserting rows into `filters`: 0 rows [00:00, ? rows/s]Inserting rows into `filters`: 3 rows [00:00, 538.79 rows/s]
Inserted 3 rows with 0 errors.
3 rows inserted, 6 values computed.
Iterate: apply filters to a few images first
Add: apply filters to 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.
3 rows updated, 3 values computed.
View results
Compare original and filtered images.Explanation
How the filter technique works: The UDFs wrap PIL’sImageFilter module to apply convolution-based
filters to images. Each filter uses a predefined kernel that processes
pixel neighborhoods to achieve different effects. Blur averages
surrounding pixels to reduce detail, Sharpen enhances pixel differences
to increase detail, Find Edges detects boundaries between contrasting
regions, and Edge Enhance strengthens edges while preserving the full
image. You can apply multiple filters to the same image to create
different versions for analysis or visual effects.
To customize the UDFs:
- Blur intensity: Use
ImageFilter.BoxBlur(radius)orImageFilter.GaussianBlur(radius)for adjustable blur strength - Edge detection: Combine with grayscale conversion for clearer edge maps
- Filter stacking: Apply multiple filters in sequence for complex effects
- Custom kernels: Use
ImageFilter.Kernel()to define your own convolution filters
.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.