A Polars plugin for vision/array operations
Project description
polars-cv
ℹ️ Note: This is a largely AI developed project and still in its early stages. Use at your own discretion.
A Polars plugin for vision/array operations, powered by view-buffer.
Features
- Lazy Pipeline Definition: Define image processing pipelines outside DataFrame context
- Expression Arguments: Use Polars expressions for dynamic, per-row parameters
- Zero-Copy Where Possible: Leverages view-buffer's stride-aware operations
- Multiple Source/Sink Formats: PNG, JPEG, NumPy, PyTorch, and more
Installation
# From source (requires Rust toolchain)
cd polars-cv
maturin develop --release
# Or with pip (once published)
pip install polars-cv
ℹ️ Note:
Polars typically operates on relatively small row sizes, which may require changing thePOLARS_IDEAL_MORSEL_SIZEenvironment variable to a smaller value, to avoid memory allocation issues.
You can set it like this before importing polars:import os os.environ["POLARS_IDEAL_MORSEL_SIZE"] = "10"
Quick Start
import polars as pl
from polars_cv import Pipeline
# Define a static pipeline
pipe = (
Pipeline()
.source("image_bytes")
.resize(height=224, width=224)
.grayscale()
.normalize(method="minmax")
.sink("numpy")
)
# Apply to DataFrame
df = pl.DataFrame({"images": [img1_bytes, img2_bytes]})
result = df.with_columns(processed=pl.col("images").cv.pipeline(pipe))
Dynamic Pipelines
Use Polars expressions for per-row parameter values:
# Dynamic pipeline with expression arguments
pipe = (
Pipeline()
.source("image_bytes")
.resize(height=pl.col("target_h"), width=pl.col("target_w"))
.crop(top=pl.col("crop_y"), left=pl.col("crop_x"), height=100, width=100)
.sink("numpy")
)
df = pl.DataFrame({
"images": [img1_bytes, img2_bytes],
"target_h": [224, 256],
"target_w": [224, 256],
"crop_x": [10, 20],
"crop_y": [5, 15],
})
result = df.with_columns(processed=pl.col("images").cv.pipeline(pipe))
Pipeline Operations
Source Formats
| Format | Description |
|---|---|
image_bytes |
Decode PNG/JPEG/WebP (auto-detect) |
blob |
VIEW protocol binary |
raw |
Raw bytes (requires dtype) |
file_path |
Read from file path |
Operations
View Operations (Zero-Copy)
transpose(axes)- Permute dimensionsreshape(shape)- Reshape arrayflip(axes)/flip_h()/flip_v()- Flip along axescrop(top, left, height, width)- Crop region
Compute Operations
cast(dtype)- Change data typescale(factor)- Multiply by factornormalize(method)- MinMax or ZScore normalizationclamp(min, max)- Clamp to range
Image Operations
resize(height, width, filter)- Resize imagegrayscale()- Convert to grayscalethreshold(value)- Binary thresholdblur(sigma)- Gaussian blur
Sink Formats
| Format | Description |
|---|---|
numpy |
NumPy-compatible bytes |
torch |
PyTorch-compatible bytes |
png |
Re-encode as PNG |
jpeg |
Re-encode as JPEG (with quality) |
blob |
VIEW protocol (for chaining) |
array |
Polars Array type (fixed shape) |
list |
Polars nested List (variable shape) |
Shape Hints
Provide shape information to help pipeline planning:
pipe = (
Pipeline()
.source("image_bytes")
.assert_shape(height=256, width=256, channels=3)
.resize(height=224, width=224)
.sink("numpy")
)
Working with List Columns
For batch processing (list of images per row):
batch_df = pl.DataFrame({
"image_batches": [[img1, img2], [img3, img4, img5]],
})
result = batch_df.with_columns(
pl.col("image_batches").list.eval(
pl.element().cv.pipeline(pipe)
)
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_cv-0.4.0-cp39-abi3-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: polars_cv-0.4.0-cp39-abi3-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 9.8 MB
- Tags: CPython 3.9+, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c85eef31b6f4d5702719b82ba92dcaea010e7de6689e50a92396c7ee4c88446
|
|
| MD5 |
d590e5eb1585331a4a84982c30be8b58
|
|
| BLAKE2b-256 |
e3e0aa90cd1d79284e1e0272fd1b60d0280d570a58593896f5f32be651047487
|
File details
Details for the file polars_cv-0.4.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: polars_cv-0.4.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 7.2 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69b38e53a6d9786e49a3bc1281f74e115957b90f803462d0d134ef3bf3ff86f5
|
|
| MD5 |
c127178928075ac2edbfc3759edac458
|
|
| BLAKE2b-256 |
ea0070c78b5f908948d8b27ab96732e33bcd0a4c2a6702356e33ef56b01bf034
|