Skip to main content

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")
)

Source Behavior (Auto DType)

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, or f64

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 dtype in source(...)
  • 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, 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 .bbox namespace).
  • 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().
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polars_cv-0.10.0.tar.gz (996.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

polars_cv-0.10.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

polars_cv-0.10.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

polars_cv-0.10.0-cp39-abi3-macosx_11_0_arm64.whl (8.6 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file polars_cv-0.10.0.tar.gz.

File metadata

  • Download URL: polars_cv-0.10.0.tar.gz
  • Upload date:
  • Size: 996.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polars_cv-0.10.0.tar.gz
Algorithm Hash digest
SHA256 7b054da429703532316cf78c525911912c23f3c973369721a32e18c21d8cb9fe
MD5 a59750f85b561e2fc87f0bc6af4a7a45
BLAKE2b-256 d3a37af5df0d9bcf9baf8e40fd946c36c3566b14ed2a33f6e2085e117360e61d

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_cv-0.10.0.tar.gz:

Publisher: publish.yml on heshamdar/polars-cv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polars_cv-0.10.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_cv-0.10.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3c311eb038e5cca2721063ac975bbb6e881ecc803e49a2e83effbd2d1344ed22
MD5 718ff5f6526becd9066bc63df44c7015
BLAKE2b-256 5b40fe8ba6f9724c13256a38638bb839eeb922858a83b570ca1e49936270b52f

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_cv-0.10.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on heshamdar/polars-cv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polars_cv-0.10.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for polars_cv-0.10.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 16651d6602aa1ad45cf2c2ad99e7c5b04b865cc4df8742faec4d0f750d5774ad
MD5 0875b13be5fb133c9b463993f730c357
BLAKE2b-256 69b4ac5cb70c284e5a854d12869394ebc117b1aff63b22fe2d30aeb4ac060c9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_cv-0.10.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on heshamdar/polars-cv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polars_cv-0.10.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_cv-0.10.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 82bf3ca4dd21f97e5012eb3e3ddb33ff701b238eafa4acf5a555cbbbd627abd6
MD5 3a43c4122bcf0897f9db66d723136e59
BLAKE2b-256 fc2bfc1dcc5703acdeedcc3b24fb51f92a75069d3f49067057887ad35d8d6a12

See more details on using hashes here.

Provenance

The following attestation bundles were made for polars_cv-0.10.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on heshamdar/polars-cv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page