Albucore: High-Performance Image Processing Functions
Albucore is a library of optimized atomic functions designed for efficient image processing. These functions serve as the foundation for AlbumentationsX, an image augmentation library.
Citing AlbumentationsX
If you use Albucore as part of an AlbumentationsX pipeline, please cite AlbumentationsX: One Augmentation Pipeline for Images and Related Annotations. Your citation makes the project's research impact visible to funders and helps sustain maintenance.
@article{iglovikov2026albumentationsx,
title = {AlbumentationsX: One Augmentation Pipeline for Images and Related Annotations},
author = {Iglovikov, Vladimir},
journal = {arXiv preprint arXiv:2608.11123},
year = {2026},
doi = {10.48550/arXiv.2608.11123},
url = {https://arxiv.org/abs/2608.11123}
}
Overview
Image processing operations can be implemented in several ways, with performance depending on dtype, size, layout, and channel count. Albucore routes each operation to a benchmark-selected NumPy, OpenCV, NumKong, StringZilla, or eligible CPU PyTorch implementation.
Image routers accept uint8, float16, and float32; float64 image inputs are not supported. NumPy uses channel-last layouts, while eager CPU Torch calls use explicit channel-first layouts where channel semantics matter. The two specialized uint8 LUT APIs remain uint8-only.
Key features:
- Optimized atomic image processing functions
- Automatic selection of the fastest implementation based on input image characteristics
- Seamless integration with AlbumentationsX
- Reproducible micro-benchmarks and committed routing reports (see benchmarks/README.md)
Installation
Requires Python 3.11+. CI covers Python 3.11, 3.12, 3.13, and 3.14. Choose and install the PyTorch build for your CPU, CUDA, or MPS environment first. Then install Albucore with an OpenCV extra. For a Linux CPU-only headless application:
pip install "torch>=2.14.1" --index-url https://download.pytorch.org/whl/cpu
pip install "albucore[headless,torch]"
CUDA or macOS (MPS): Select and install the matching PyTorch build with the PyTorch installation selector, then install Albucore:
pip install "albucore[headless,torch]"
pip install albucore installs only the base dependency set. Use it when a transitive consumer only resolves
Albucore, such as during a documentation build. The current public import graph requires both OpenCV and PyTorch.
The torch extra declares Albucore's PyTorch runtime requirement but cannot select a CPU, CUDA, or MPS wheel through
standard package metadata. Use PyTorch's platform-specific installation command before installing Albucore. The examples
use the headless OpenCV extra. When Albucore installs OpenCV, choose exactly one extra: headless, gui,
contrib, or contrib-headless. Use albucore[torch] when reusing an existing OpenCV installation.
AlbumentationsX passes prevalidated CPU, strided Torch tensors with requires_grad=False to
resize3d and warp_affine3d; the low-level routers do not repeat those checks or move/detach Tensor data.
warp_affine3d and remap3d also accept rank-5 volume batches with one shared affine matrix or pull grid.
With OpenCV GUI support (for local development with cv2.imshow):
pip install "albucore[gui,torch]"
With OpenCV contrib modules:
pip install "albucore[contrib,torch]" # GUI version
pip install "albucore[contrib-headless,torch]" # Headless version
Note: If you already have one of the supported OpenCV distributions installed, use pip install "albucore[torch]"
after installing the platform-specific PyTorch build. This does not add another OpenCV package; Albucore uses the
existing installation.
Usage
import numpy as np
import albucore
# Create a sample RGB image
image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
# Apply a function
result = albucore.multiply(image, 1.5)
# For grayscale images, ensure the channel dimension is present
gray_image = np.random.randint(0, 256, (100, 100, 1), dtype=np.uint8)
gray_result = albucore.multiply(gray_image, 1.5)
Albucore automatically selects the most efficient implementation based on the input image type and characteristics.
Shape Conventions
Albucore expects images to follow specific shape conventions, with the channel dimension always present:
- Single image:
(H, W, C)- Height, Width, Channels - Grayscale image:
(H, W, 1)- Height, Width, 1 channel - Batch of images:
(N, H, W, C)- Number of images, Height, Width, Channels - 3D volume:
(D, H, W, C)- Depth, Height, Width, Channels
These are NumPy layouts. CPU Torch uses CHW, NCHW, CDHW, or NCDHW; common operations that need a channel axis take an explicit layout= keyword.
Important Notes:
- Channel dimension is always required, even for grayscale images (use shape
(H, W, 1)) - Single-channel images should have shape
(H, W, 1)not(H, W) - Batch vs volume:
(N, H, W, C)is N separate images; a single NumPy 3D volume is(D, H, W, C).warp_affine3dandremap3dalso accept NumPy volume batches(N, D, H, W, C). Do not confuseN(batch) withD(slices).
Examples:
import numpy as np
import albucore
# Grayscale image - MUST have explicit channel dimension
gray_image = np.random.randint(0, 256, (100, 100, 1), dtype=np.uint8)
# RGB image
rgb_image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
# Batch of 10 grayscale images
batch_gray = np.random.randint(0, 256, (10, 100, 100, 1), dtype=np.uint8)
# 3D volume with 20 slices
volume = np.random.randint(0, 256, (20, 100, 100, 1), dtype=np.uint8)
Functions
The tables below highlight commonly used public routers. They are exported via from albucore import *. The
compatibility shims in albucore.functions cover only the names documented in docs/public-api.md;
warp_affine3d is intentionally public from albucore and albucore.geometric only.
NumPy image routers use channel-last inputs with an explicit channel dimension ((H, W, C), never bare (H, W)). CPU Torch calls use channel-first layouts (CHW, NCHW, CDHW, NCDHW); pass layout= to common operations when channel semantics matter. Image routers support uint8, float16, and float32, except where a table states a narrower dtype contract.
Arithmetic
| Function | Signature | What it does | How it works |
|---|---|---|---|
multiply |
(img, value, inplace=False, *, layout=None) |
Floating results preserve input dtype; uint8 saturates | uint8 scalar/vector → LUT; float16 HWC C=1 uses NumKong scale with neonhalf=true for exact half controls from 20,480 elements; C=3 uses OpenCV CV16F for exact half controls from 61,440 elements; other float16/float32 paths are benchmark-selected |
add |
(img, value, inplace=False, *, layout=None) |
Floating results preserve input dtype; uint8 saturates | uint8 uses OpenCV/LUT/NumKong; float16 HWC C=1 uses NumKong scale with neonhalf=true for exact half controls from 20,480 elements; C=3 uses OpenCV CV16F for exact half controls from 61,440 elements; other float16/float32 paths are benchmark-selected |
power |
(img, exponent, inplace=False, *, layout=None) |
Floating results preserve input dtype; uint8 saturates | uint8 → LUT; float32 scalar → cv2.pow; float16 scalar widens for OpenCV then restores half |
add_weighted |
(img1, weight1, img2, weight2, *, layout=None) |
Floating results preserve input dtype; uint8 saturates | NumKong is used for selected uint8/float32 regions; float16 uses a benchmark-selected CPU route |
multiply_add |
(img, factor, value, inplace=False, *, layout=None) |
Floating results preserve input dtype; uint8 saturates | uint8 → LUT; float32 scalar → NumKong scale; float16 and other controls use measured NumPy/Torch paths |
value / factor / exponent can be a scalar, a length-C 1-D array (per-channel), or a
full image-shaped array.
These arithmetic routers do not impose an image-range convention on floating-point data. The explicit
@clipped decorator remains available for callers, including AlbumentationsX operations whose own
contract requires clipping.
Elementwise math
| Function | Signature | What it does | How it works |
|---|---|---|---|
exp |
(array, *, inplace=False) |
Elementwise exponential; float16/float32 preserve dtype, uint8 returns float32 | NumPy, OpenCV, or CPU Torch by dtype and measured region |
log |
(array, *, inplace=False) |
NumPy-compatible natural logarithm; float16/float32 preserve dtype, uint8 returns float32 | NumPy special values; guarded OpenCV or Torch paths for eligible regions |
sqrt |
(array, *, inplace=False) |
NumPy-compatible square root; float16/float32 preserve dtype, uint8 returns float32 | NumPy or CPU Torch by dtype and measured region |
These functions preserve the input shape. With inplace=True, an owned writable buffer may be reused; views and read-only arrays are never mutated. See the elementwise benchmark report for routing thresholds, environment, and NumKong results.
Normalization
| Function | Signature | What it does | How it works |
|---|---|---|---|
normalize |
(img, mean, denominator, *, layout=None) |
Float16 input returns float16; uint8/float32 return float32 | uint8 → LUT; float16/float32 use benchmark-selected CPU paths. Caller-supplied constants (e.g. ImageNet stats). |
normalize_per_image |
(img, normalization, *, layout=None) |
Float16 input returns float16; uint8/float32 return float32 | uint8 → LUT; floating inputs use OpenCV/NumPy working paths. normalization ∈ {"image", "image_per_channel", "min_max", "min_max_per_channel"} |
normalize is for fixed per-channel constants (ImageNet-style).
normalize_per_image estimates stats from the image at call time.
Statistics
| Function | Signature | What it does | How it works |
|---|---|---|---|
mean |
(arr, axis=None, *, keepdims=False, dtype=None, layout=None) |
Population mean, wide output | uint8 and floating inputs use NumKong, OpenCV, Torch, or NumPy by region |
std |
(arr, axis=None, *, keepdims=False, eps=1e-4, dtype=None, layout=None) |
Population std + eps, wide output | NumKong moments, OpenCV, Torch, or NumPy by region |
mean_std |
(arr, axis=None, *, keepdims=False, eps=1e-4, layout=None) |
Mean and std+eps jointly | Wide-accumulator routes selected by input dtype and layout |
reduce_sum |
(arr, axis=None, *, keepdims=False, layout=None) |
Sum with wide accumulator | uint8 → uint64; floating inputs → float64 with Torch, NumKong, or NumPy by region |
axis accepts None/"global" (scalar), "per_channel" (shape (C,)), or any NumPy-style
int/tuple[int, ...].
LUT (lookup tables)
| Function | Signature | What it does | How it works |
|---|---|---|---|
apply_uint8_lut |
(img, lut, *, inplace=False) |
Apply uint8→uint8 LUT; lut shape (256,) or (C, 256) |
Shared (256,): StringZilla or cv2.LUT by size heuristic. Per-channel (C, 256): single cv2.LUT with (256,1,C) table on contiguous HWC; else StringZilla per channel |
sz_lut |
(img, lut, inplace=True) |
Apply shared (256,) uint8 LUT via StringZilla translate |
Raw byte translation — channel-unaware, fastest for small images and single-channel |
Geometric / spatial
| Function | Signature | What it does | How it works |
|---|---|---|---|
hflip |
(img) |
Mirror left-right | NumPy slice view for every channel count; hflip_cv2 remains the explicit materializing backend |
vflip |
(img) |
Mirror top-bottom | NumPy slice view for every channel count; vflip_cv2 remains the explicit materializing backend |
median_blur |
(img, ksize, *, layout=None) |
Median filter (odd ksize ≥ 3) | uint8 → direct/chunked OpenCV; float16/float32 use the documented OpenCV working paths |
pad3d |
(volume, padding, value=0) |
Add constant borders to uint8/float16/float32 volumes or int16 masks | NumPy fill/copy or CPU Torch F.pad; preserves NumPy DHWC or Tensor CDHW |
gaussian_blur3d |
(volume, sigma, kernel_size=0) |
Blur one volume along depth, height, and width | One NumPy DHWC or CPU Torch CDHW volume; float32 working passes where needed, then restore the output dtype |
separable_filter3d |
(volume, kernels) |
Apply three D/H/W kernels to one volume | One NumPy DHWC or CPU Torch CDHW volume; float32 working passes where needed, then restore the output dtype |
warp_affine3d |
(volume, matrix, size, interpolation, border_mode, border_value) |
Apply one forward 3D affine matrix to a volume or batch | NumPy DHWC/NDHWC or CPU Torch CDHW/NCDHW; one matrix is shared across the batch; native Torch affine_grid + grid_sample |
remap3d |
(volume, sampling_grid, interpolation, border_mode, border_value) |
Sample a volume or batch through one shared normalized 3D pull grid | NumPy DHWC/NDHWC or CPU Torch CDHW/NCDHW; grid layout (D_out, H_out, W_out, 3) |
matmul |
(a, b) |
Matrix multiply (a @ b) |
NumPy @ (BLAS-backed); float16 uses float32 accumulation and casts back |
pairwise_distances_squared |
(points1, points2) |
Squared Euclidean distance matrix (N, M) |
Small (N*M < 1000) → NumKong cdist; large → NumPy vectorized ‖a‖²+‖b‖²−2(a·b) |
The package also star-exports copy_make_border, gaussian_blur3d, pad3d, remap, remap3d, resize, resize3d, separable_filter3d, warp_affine, warp_affine3d, and warp_perspective; see docs/public-api.md and their docstrings for complete signatures. gaussian_blur3d, pad3d, separable_filter3d, and resize3d expect one NumPy DHWC volume or CPU Torch CDHW tensor per call. warp_affine3d and remap3d accept those single-volume layouts or NumPy NDHWC and CPU Torch NCDHW batches.
Type conversion
| Function | Signature | What it does | How it works |
|---|---|---|---|
to_float |
(img, max_value=None) |
Convert uint8 to float32 in [0, 1]; float16 and float32 are unchanged | float32/float16 → no-op; uint8 → cv2.LUT (256-entry float32 table) |
from_float |
(img, target_dtype, max_value=None) |
Convert floats to a target dtype; integer targets scale, round, and clip | Floating targets cast without scaling; NumPy float16→uint8 widens to float32 for exact rounding; float32→uint8 uses the routed fast path |
Decorators (re-exported)
| Decorator | What it does |
|---|---|
float32_io |
Wrap a function: cast input to float32, cast output back to original dtype |
uint8_io |
Wrap a function: cast input to uint8, cast output back to original dtype |
See docs/decorators.md for @preserve_channel_dim and @clipped.
Array layouts and batch processing
NumPy arithmetic, normalization, statistics, conversion, and elementwise routers use channel-last layouts:
- Single images:
(H, W, C) - Batches:
(N, H, W, C) - Single volumes:
(D, H, W, C)
Spatial routers document their own image-shape requirements. CPU Torch calls use CHW, NCHW, CDHW, or NCDHW. Pass keyword-only layout= to common operations when channel controls or reductions depend on the channel axis. Spatial APIs such as resize and resize3d define their layout by the operation.
See docs/decorators.md for internal decorator documentation (@preserve_channel_dim, @clipped).
Performance
Albucore uses a combination of techniques to achieve high performance:
- Multiple Implementations: Each function may have several implementations using NumPy, OpenCV, NumKong, StringZilla, or CPU PyTorch when the documented contract permits it.
- Automatic Selection: The library chooses a backend from dtype, size, memory layout, channel count, and semantic constraints.
- Measured Routing: Backend choices and thresholds come from repeatable benchmarks rather than backend preference.
- NumKong: SIMD
blendfor uint8 and single-channel float32add_weighted, plus same-shaped uint8add_array;cdistfor smallpairwise_distances_squared; wide-accumulatormomentsfor selected statistics routes (see docs/numkong-performance.md). - CPU PyTorch: Selected eager 3D volume operations use full-path Torch routes after benchmarks include the NumPy/Tensor bridge, thread settings, and output repair (see docs/torch-performance-optimization.md).
Micro-benchmarks vs NumPy/OpenCV/NumKong: see benchmarks/README.md. Run uv run python benchmarks/benchmark_elementwise.py for exp/log/sqrt, or uv run python benchmarks/benchmark_numkong.py for a smaller NumKong sweep.
See docs/performance-optimization.md for the general workflow and docs/torch-performance-optimization.md for eager CPU Torch routes.
Documentation
- CONTRIBUTING.md - Pull request process and CLA acceptance paths
- AGENTS.md - AI development guidelines for working with this codebase
- docs/image-conventions.md - Image shape conventions and requirements
- docs/decorators.md - Decorator usage and patterns
- docs/performance-optimization.md - Performance optimization guidelines
- docs/torch-performance-optimization.md - Eager CPU PyTorch routing and benchmark guidance
- docs/numkong-performance.md - Current NumKong routes and benchmark decisions
- docs/public-api.md - Star-exported routers vs
albucore.functionsshims - benchmarks/README.md - Python micro-benchmarks (
uv run python benchmarks/…)
License
Albucore is publicly available under the MIT License, including contributions accepted under the Albucore Contributor License Agreement Version 1.0. The CLA does not change the repository's public license. Historical contributions remain available under MIT and become CLA-covered only through an applicable Version 1.0 Acceptance Record. See CONTRIBUTING.md for the individual CLA Assistant and entity acceptance paths.
Acknowledgements
Albucore provides core image-processing primitives for AlbumentationsX. We'd like to thank all AlbumentationsX contributors and the broader computer vision community for their inspiration and support.
Metadata
Release files for albucore 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| albucore-0.3.0.tar.gz | 222.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| albucore-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 303.4 kB
Release files / albucore-0.3.0.tar.gz
| Download URL | albucore-0.3.0.tar.gz |
|---|---|
| Size | 222.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
626e5a57062012ae821138383f1de5498398e4044a85909a460373603fcf79e6
|
|
BLAKE2b-256 checksum How to use checksums |
d08165595ca512b47baf9f0c7574b539564686f138cc4cca5d2120101da9ccea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency logRelease files / albucore-0.3.0-py3-none-any.whl
| Download URL | albucore-0.3.0-py3-none-any.whl |
|---|---|
| Size | 81.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7e40f16666a4df5ba5ae4081c572250dbeee430f1af5f62150a0cf7be46392f
|
|
BLAKE2b-256 checksum How to use checksums |
f4bf1b4af146a1ac2d4a813ca7c545657d0c8d869abd584ec33089d8d5fdd832
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency log