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 high-performance vision and array operations.
Features
- Modular Pipelines: Define image processing pipelines and apply them to DataFrame columns.
- Expression Arguments: Use Polars expressions for dynamic, per-row parameters.
- Zero-Copy Performance: Efficient memory management with stride-aware operations.
- Multi-Domain: Seamlessly move between images, geometry (contours), and numeric results.
Installation
pip install polars-cv
Quick Start
import polars as pl
from polars_cv import Pipeline
# Define a pipeline and apply it to a column
pipe = Pipeline().source("image_bytes").resize(height=224, width=224).grayscale()
df = pl.DataFrame({"image": [img1_bytes, img2_bytes]})
result = df.with_columns(
processed=pl.col("image").cv.pipe(pipe).sink("numpy")
)
Scaling to Large Datasets (Streaming)
The .cv.pipe(...) expression is a normal elementwise Polars plugin, so the
parallelism comes from Polars' engine, not from inside the plugin. On a
plain DataFrame.with_columns(...)/.select(...) call (eager), the whole
column is processed on a single thread. For larger-than-a-handful image
workloads, run through the lazy streaming engine instead — Polars splits the
column into morsels and processes them across its worker pool, and can spill
intermediate state to disk when memory is tight:
result = (
df.lazy()
.with_columns(processed=pl.col("image").cv.pipe(pipe).sink("blob"))
.collect(engine="streaming")
)
This is the recommended path for anything beyond small/interactive use; the
plugin's per-morsel graph is cached, so per-morsel overhead is just a hash
lookup. (The detection-metrics APIs already collect with
engine="streaming" internally.)
Source Behavior (Auto DType)
source() defaults to "auto", which infers the decode path from the input
column's dtype: String → file_path, List/Array → list/array, and
Binary → blob when it carries the VIEW protocol magic, image_bytes
otherwise. Pass an explicit format to override it.
image_bytes and file_path sources decode image format and dtype at runtime:
- PNG/JPEG usually decode as
u8 - 16-bit PNG decodes as
u16 - TIFF may decode as
u8,u16,f32, orf64
This means the pipeline dtype starts as auto for these sources unless you pin it with dtype=... or an operation that determines dtype (such as normalize, threshold, or cast).
# Runtime decode with automatic dtype
auto_pipe = Pipeline().source("image_bytes").resize(height=224, width=224)
# Pin expected dtype at source (runtime cast when needed)
typed_pipe = Pipeline().source("image_bytes", dtype="f32").resize(height=224, width=224)
When using sink("list") or sink("array"), dtype must be known at planning time. For image_bytes / file_path, choose one of:
- set
dtypeinsource(...) - add
.cast("...") - use a dtype-fixing operation before the sink
pipe = Pipeline().source("file_path", dtype="f32").resize(height=224, width=224)
result = df.with_columns(values=pl.col("path").cv.pipe(pipe).sink("list"))
Dynamic Pipelines
Use Polars expressions for per-row parameter values:
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)
)
df = pl.DataFrame({
"image": [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("image").cv.pipe(pipe).sink("numpy")
)
Operations
- Image:
resize,resize_scale,resize_to_height,resize_to_width,resize_max,resize_min,thumbnail,grayscale,blur,threshold,crop,rotate,pad,letterbox,flip_h,flip_v. - Color:
cvt_color,to_hsv,to_lab,to_bgr,to_ycbcr. - Channels:
channel_select,channel_swap. - Intensity:
adjust_contrast,adjust_gamma,adjust_brightness,invert. - Convolution & Edge Detection:
convolve2d,sobel,laplacian,sharpen,canny. - Morphology:
erode,dilate,morphology_open,morphology_close,morphology_gradient. - Affine Transforms:
warp_affine,shear,rotate_and_scale(with automatic pipeline fusion). - Enhancement:
equalize_histogram. - Compute:
normalize,scale,clamp,relu,cast. - Layout:
transpose,reshape. - Geometry:
extract_contours,rasterize,area,perimeter,centroid,bounding_box. - Points:
normalize,translate,scale,rotate,distance,manhattan_distance,distance_to_contour,signed_distance_to_contour,nearest_point_on_contour,angle_to,midpoint,interpolate,within_bbox. - Bounding Boxes:
pairwise_iou,match_detections(via.bboxnamespace). - Analysis:
histogram,perceptual_hash,extract_shape,label_reduce. - Reductions:
reduce_sum,reduce_mean,reduce_std,reduce_max,reduce_min,reduce_argmax,reduce_argmin,reduce_percentile,reduce_popcount. - Metadata:
.cv.width(),.cv.height(),.cv.channels(),.cv.image_dtype(). - Byte access:
.cv.read_bytes()— read a path column's bytes (local or cloud) without decoding. - Display:
show_images()for Jupyter notebook visualization. - Detection Metrics: Precision-Recall, AP, mAP, FROC, LROC, F1, confusion matrix, bootstrap confidence intervals.
Detection Metrics
Evaluate object detectors with industry-standard metrics:
from polars_cv.metrics import PreMatchedAdapter, precision_recall_curve, average_precision
# Wrap pre-matched detection data
adapter = PreMatchedAdapter()
table = adapter.match(df, pred_col="confidence", gt_col="is_tp", image_id_col="slide_id")
# Compute metrics
pr = precision_recall_curve(table)
ap = average_precision(table)
print(f"AP: {ap:.3f}")
print(pr.summary_table())
Available matchers: ContourMatcher (heatmap/mask), BBoxMatcher (bounding boxes),
PreMatchedAdapter (pre-computed TP/FP).
Available metrics: precision_recall_curve, average_precision,
mean_average_precision, froc_curve, lroc_curve, confusion_at_threshold,
precision_at_threshold, recall_at_threshold, f1_at_threshold.
For full details, see the Documentation
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 Distribution
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.15.0.tar.gz.
File metadata
- Download URL: polars_cv-0.15.0.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20fac7717389e16b887271be2d66e7de43ca9a86f895507acdf3952193967629
|
|
| MD5 |
953f8c2adecd74af167bb1b987d6e088
|
|
| BLAKE2b-256 |
0c4325daf4b3a84f24ff5eb82966d49528ff4a9accde97100c8b77a5d8d3f341
|
Provenance
The following attestation bundles were made for polars_cv-0.15.0.tar.gz:
Publisher:
publish.yml on heshamdar/polars-cv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_cv-0.15.0.tar.gz -
Subject digest:
20fac7717389e16b887271be2d66e7de43ca9a86f895507acdf3952193967629 - Sigstore transparency entry: 2255876638
- Sigstore integration time:
-
Permalink:
heshamdar/polars-cv@3e12017e874d74cbf6034579bc261d85ffb6b381 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/heshamdar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e12017e874d74cbf6034579bc261d85ffb6b381 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file polars_cv-0.15.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: polars_cv-0.15.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 10.5 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7691f25086da8d0a8404e73381475229769b5b5f1ed477af530279e5e8e46322
|
|
| MD5 |
f495443afe3c7f5cde96dbd21d88fcff
|
|
| BLAKE2b-256 |
695e640eb4f0674ff9095489547d606d4e03639261e0a1488719c0bb37ee6aa3
|
Provenance
The following attestation bundles were made for polars_cv-0.15.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on heshamdar/polars-cv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_cv-0.15.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
7691f25086da8d0a8404e73381475229769b5b5f1ed477af530279e5e8e46322 - Sigstore transparency entry: 2255876658
- Sigstore integration time:
-
Permalink:
heshamdar/polars-cv@3e12017e874d74cbf6034579bc261d85ffb6b381 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/heshamdar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e12017e874d74cbf6034579bc261d85ffb6b381 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file polars_cv-0.15.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: polars_cv-0.15.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 9.4 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efdbc017da1aa80f262937b74c3433c24d39138efeec0deb5f045e7711c5f375
|
|
| MD5 |
7b335f0c653b9021cf04c60b394a7a55
|
|
| BLAKE2b-256 |
5ed5b48631b51b49995d78938d2d6d842bce243bb006a1bf6364204003147df4
|
Provenance
The following attestation bundles were made for polars_cv-0.15.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
publish.yml on heshamdar/polars-cv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_cv-0.15.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
efdbc017da1aa80f262937b74c3433c24d39138efeec0deb5f045e7711c5f375 - Sigstore transparency entry: 2255876690
- Sigstore integration time:
-
Permalink:
heshamdar/polars-cv@3e12017e874d74cbf6034579bc261d85ffb6b381 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/heshamdar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e12017e874d74cbf6034579bc261d85ffb6b381 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file polars_cv-0.15.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: polars_cv-0.15.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 9.2 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08eb610892ffbf5b17ce86be1de4e954ded0e6d3df55edfcaddcdf965cac1f70
|
|
| MD5 |
7b1d9cac2057cdb49d2287ba00a55293
|
|
| BLAKE2b-256 |
3369ffe04198841cd6cc3614187e4ab18ec994a971c23d51f8b249d360d9c891
|
Provenance
The following attestation bundles were made for polars_cv-0.15.0-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
publish.yml on heshamdar/polars-cv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_cv-0.15.0-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
08eb610892ffbf5b17ce86be1de4e954ded0e6d3df55edfcaddcdf965cac1f70 - Sigstore transparency entry: 2255876682
- Sigstore integration time:
-
Permalink:
heshamdar/polars-cv@3e12017e874d74cbf6034579bc261d85ffb6b381 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/heshamdar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e12017e874d74cbf6034579bc261d85ffb6b381 -
Trigger Event:
workflow_dispatch
-
Statement type: