Skip to main content

wsidicom-kernels

Fast, accurate resizing and downscaling for numpy arrays, written in Rust with SIMD kernels — for image pyramids, reads of missing pyramid levels and thumbnails:

  • resize — any exact target size (fractional ratios, upscaling), antialiased at every ratio.
  • downscale — reduce by an integer factor: power-of-2 box (native SIMD, ~2× faster than Pillow reduce) and bilinear / catmullrom / lanczos3 (Lanczos ~8× faster than Pillow LANCZOS). The scale is exactly the factor and the output ceil(size / factor), as Pillow reduce and libvips shrink: where the factor doesn't divide the size, the last row and column cover what remains (with box, the mean of those pixels; bit-identical to Pillow reduce(2)), rather than the image being stretched or cropped.
  • downscale_grid — downscale of a grid of tiles stitched row-major, such as the four children of a pyramid tile, optionally into a filled frame of a given size; with box each tile is reduced straight into its place.
  • All resampling is native, on every CPU: uint8 and uint16 within 1 LSB of the exact convolution at any ratio (see What runs where).

Works on planar (H, W) or interleaved RGB (H, W, 3) arrays, dtype uint8 / uint16. Subsampled chroma (YCbCr 4:2:0) is resized per plane.

Usage

import numpy as np
from wsidicom_kernels import (
    ResizeFilter,
    downscale,
    downscale_grid,
    resize,
)

rng = np.random.default_rng(0)
image = rng.integers(0, 256, (1023, 1023, 3), np.uint8)

# downscale: reduce by an integer factor; image array in, new array out.
# Output size is ceil(size / factor): 1023 pixels by 2 gives 512.
half = downscale(image, 2, ResizeFilter.BOX)  # (512, 512, 3)
quarter = downscale(image, 4, ResizeFilter.LANCZOS3)  # (256, 256, 3)

# resize: resample to an exact (height, width), any ratio, up or down.
sized = resize(image, 300, 400, ResizeFilter.CATMULLROM)  # (300, 400, 3)

# downscale_grid: four 512 x 512 child tiles (row-major, 2 per row) into one
# parent tile; size and fill frame a partial block at the image's edge.
children = [rng.integers(0, 256, (512, 512, 3), np.uint8) for _ in range(4)]
fill = np.array([255, 255, 255], np.uint8)
parent = downscale_grid(
    children, 2, 2, ResizeFilter.BOX, size=(512, 512), fill=fill
)  # (512, 512, 3)

What runs where

wsidicom-kernels's own kernels do the power-of-2 box reductions and every convolution resize, on x86-64 and aarch64 alike; its convolution follows fast_image_resize's filters and windows.

Operation Computed by
downscale / resize with "box" at an exact power-of-2 factor wsidicom-kernels
downscale / resize of uint8, with box / bilinear / catmullrom / lanczos3 — any ratio up or down wsidicom-kernels
nearest, every dtype (fast_image_resize's sample positions) wsidicom-kernels
downscale / resize of uint16, with box / bilinear / catmullrom / lanczos3 — any ratio (computed in f32; within 1 LSB of exact) wsidicom-kernels

The native path computes the same convolution as fast_image_resize (same filters, windows and edge handling) but within 1 LSB of the exact result at any ratio. uint8 runs in 16-bit fixed point down to 1/128 per axis, where each filter tap rounds to the nearest 1/64 LSB; larger uint8 reductions take the f32 engine of uint16 (2–3x slower than fixed point would be, but fixed point's roundings would add up over the long windows). That engine sums windows of more than 256 taps in chunks added in f64, so even a flat image reduced by tens of thousands keeps its value. downscale with box at a power-of-2 factor stays within 1 LSB at any factor, with the same result on every CPU (x86-64 and aarch64, SIMD or scalar). fast_image_resize rounds and clamps an intermediate: with catmullrom / lanczos3 it is off by up to ~20 LSB near sharp edges that touch 0 or 255 (elsewhere within 1 LSB too). The native results are identical on every CPU (the AVX2 and NEON kernels and the scalar fallback compute the same arithmetic), and an interleaved image gives exactly what resizing each channel as a planar image gives.

Speed against fast_image_resize on x86-64 (Ryzen 7940HS; 512² and 2048² images, 2x up to 1/8, all four filters; median and slowest case):

AVX2
uint8 planar 2.3x (1.1x)
uint8 RGB 1.3x (0.9x)
uint16, every layout 1.6-2.8x (1.0x)

Every channel is filtered on its own.

SIMD

Kernels dispatch at runtime: AVX2 on x86-64 (via is_x86_feature_detected!), NEON on aarch64 (Apple Silicon / ARM), and a scalar fallback everywhere else. The crate builds at baseline x86-64, so one binary runs on any CPU — full speed where SIMD exists, correct otherwise. No global target-cpu needed.

Environment toggle (read once per process): WSIDICOM_KERNELS_NT=0 disables non-temporal stores on large box outputs.

The GIL is released around every kernel; parallelize across tiles with Python threads (there is no internal compute threading).

Performance notes

  • Parallelize with threads, e.g. one output tile per thread: the GIL is released inside every call.

Build

Needs Rust, uv and maturin. Then:

# macOS / Linux:
uv run --with maturin --with numpy --with pytest maturin develop --release

# Windows: use ./build.ps1 (wraps vcvars64), and install the Windows SDK once:
#   winget install Microsoft.WindowsSDK.10.0.28000

Test

uv sync --all-packages      # from the repository root: the kernels dev group
uv run --all-packages pytest kernels/tests

One test file per operation (test_resize, test_downscale, test_downscale_grid), plus cross-cutting ones:

file checks
test_fuzz.py Hypothesis-generated shapes, factors and filters: resize and downscale SIMD/scalar parity, inputs flush against an unmapped page so any out-of-bounds access crashes
test_state.py resize, downscale and downscale_grid keep no state: recycled outputs full of junk, plans cached across SIMD toggles, other calls in between
test_boundary.py saturation, checkerboards
test_threads.py GIL-released concurrency: identical results on every thread
test_pillow.py bit-identity with Pillow reduce(2), partial edge boxes included

Most tests compare the SIMD kernels with the forced-scalar reference (simd_and_scalar in conftest.py).

A debug build (maturin develop without --release) additionally checks every get_unchecked precondition at runtime; run the suite against one after touching kernel bounds.

Benchmark

bench/ holds the benchmarks; bench/bench.py [filter] is the everyday one (SIMD vs forced-scalar, interleaved, per kernel). Trust ratios measured within one run, not absolute times across runs. bench/bench_libs.py compares against Pillow, OpenCV and libvips; install those with uv sync --group bench.

Metadata

Release files for wsidicom-kernels 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wsidicom-kernels 0.1.0
File Size Uploaded Provenance Actions
wsidicom_kernels-0.1.0.tar.gz 181.5 kB Without provenance Details for wsidicom_kernels-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for wsidicom-kernels 0.1.0
File Actions
wsidicom_kernels-0.1.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for wsidicom_kernels-0.1.0-cp311-abi3-win_amd64.whl
wsidicom_kernels-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details for wsidicom_kernels-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl
wsidicom_kernels-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details for wsidicom_kernels-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl
wsidicom_kernels-0.1.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for wsidicom_kernels-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
wsidicom_kernels-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for wsidicom_kernels-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 2.3 MB

Release files / wsidicom_kernels-0.1.0.tar.gz

Download URL wsidicom_kernels-0.1.0.tar.gz
Size 181.5 kB
Tags Source
SHA-256 checksum
How to use checksums
28954aa613114a727780e0ba32acb340817f485648357758377649a4ccbc3547
BLAKE2b-256 checksum
How to use checksums
5dcb4e3a2b0c056bf897599885075448c5431b1e3a968171f5462a00d54e018e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wsidicom_kernels-0.1.0-cp311-abi3-win_amd64.whl

Download URL wsidicom_kernels-0.1.0-cp311-abi3-win_amd64.whl
Size 404.0 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7874eba245111bd39c21730db90878e8ed840472efe1cad41ec169349b110e12
BLAKE2b-256 checksum
How to use checksums
70b4b8ae2aec702d0007bdaec153fa82a61eb9eda3c0adabf5330544728b924d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wsidicom_kernels-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL wsidicom_kernels-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl
Size 507.4 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
93811ed65b8c844022047c83304b6e1622a5276c0f3db7daa1aa1be71af08c11
BLAKE2b-256 checksum
How to use checksums
59c0c3e6bb72da6b7e35270f310302ce41dde5c1fb8e5f1705e46dcc3e6ba814
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wsidicom_kernels-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL wsidicom_kernels-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl
Size 398.6 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
c2d704a8c7d10c3a938ffbcff849c0a2d8635e0225fa71a7abb816f52f9fa510
BLAKE2b-256 checksum
How to use checksums
706f89230225171e74a5f65fcab4e71d037028b5119e183ef14898b82065761c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wsidicom_kernels-0.1.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL wsidicom_kernels-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Size 375.4 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
edf5e0b8780558a2a66e2357088d0494beaa992af2baa13b538dac6ec0e150cd
BLAKE2b-256 checksum
How to use checksums
c6ffa3addef35e738536646f1e9345a017c31e02eb7da5febf2b2053c04f03c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wsidicom_kernels-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL wsidicom_kernels-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 465.6 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e9e3360c30d1adb4436c86f07bef2c3413d01e827e926672aa288367881a4daa
BLAKE2b-256 checksum
How to use checksums
855f05ea9ee61b6526a766702410e0c5948acdab787d0656f9eaa09b1de9d32d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for wsidicom-kernels 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

6 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page