Skip to main content

High-performance image processing functions for deep learning and computer vision.

Project description

Albucore: High-Performance Image Processing Functions

PyPI version Python 3.10+ CI License: MIT Sponsored by GitAds

Albucore is a library of optimized atomic functions designed for efficient image processing. These functions serve as the foundation for AlbumentationsX, a popular image augmentation library.

Overview

Image processing operations can be implemented in various ways, each with its own performance characteristics depending on the image type, size, and number of channels. Albucore aims to provide the fastest implementation for each operation by leveraging different backends such as NumPy, OpenCV, and custom optimized code.

Supported dtypes: uint8 and float32 only.

Key features:

  • Optimized atomic image processing functions
  • Automatic selection of the fastest implementation based on input image characteristics
  • Seamless integration with AlbumentationsX
  • Benchmark scripts available (see ./benchmark.sh <data_dir>)

Installation

Requires Python 3.10+. Basic installation (you manage OpenCV separately):

pip install albucore

With OpenCV headless (recommended for servers/CI):

pip install albucore[headless]

With OpenCV GUI support (for local development with cv2.imshow):

pip install albucore[gui]

With OpenCV contrib modules:

pip install albucore[contrib]              # GUI version
pip install albucore[contrib-headless]     # Headless version

Note: If you already have opencv-python or opencv-contrib-python installed, just use pip install albucore to avoid package conflicts. Albucore will detect and use your existing OpenCV 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
  • Batch of volumes: (N, D, H, W, C) - Number of volumes, Depth, Height, Width, Channels

Important Notes:

  1. Channel dimension is always required, even for grayscale images (use shape (H, W, 1))
  2. Single-channel images should have shape (H, W, 1) not (H, W)
  3. Batches and volumes are treated uniformly - a 4D array (N, H, W, C) can represent either a batch of images or a 3D volume

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)

# Batch of 5 RGB volumes, each with 20 slices
batch_volumes = np.random.randint(0, 256, (5, 20, 100, 100, 3), dtype=np.uint8)

Functions

Albucore includes optimized implementations for various image processing operations:

  • Arithmetic: add, multiply, power, add_weighted, multiply_add
  • Normalization: normalize (per-channel, global), normalize_per_image
  • Geometric: hflip, vflip, warp_affine, warp_perspective, remap, copy_make_border
  • Type conversion: to_float, from_float

Batch Processing

Many functions in Albucore support batch processing out of the box. The library automatically handles different input shapes:

  • Single images: (H, W, C)
  • Batches: (N, H, W, C)
  • Volumes: (D, H, W, C)
  • Batch of volumes: (N, D, H, W, C)

Functions will preserve the input shape structure, applying operations efficiently across all images/slices in the batch.

Decorators

Albucore provides several useful decorators:

  • @preserve_channel_dim: Ensures single-channel images maintain their shape (H, W, 1) when OpenCV operations might drop the channel dimension
  • @contiguous: Ensures arrays are C-contiguous for optimal performance
  • @clipped: Clips results to valid dtype range after arithmetic operations
  • @uint8_io and @float32_io: Handle automatic type conversions for functions that work best with specific data types
  • @batch_transform: Batch processing patterns for images, volumes, and batches

See docs/decorators.md for detailed documentation on all decorators.

Performance

Albucore uses a combination of techniques to achieve high performance:

  1. Multiple Implementations: Each function may have several implementations using different backends (NumPy, OpenCV, custom code).
  2. Automatic Selection: The library automatically chooses the fastest implementation based on the input image type, size, and number of channels.
  3. Optimized Algorithms: Custom implementations are optimized for specific use cases, often outperforming general-purpose libraries.

See docs/performance-optimization.md for detailed performance guidelines and best practices.

Documentation

License

MIT

Acknowledgements

Albucore is part of the AlbumentationsX project. We'd like to thank all contributors to AlbumentationsX and the broader computer vision community for their inspiration and support.

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

albucore-0.0.38.tar.gz (27.3 kB view details)

Uploaded Source

Built Distribution

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

albucore-0.0.38-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file albucore-0.0.38.tar.gz.

File metadata

  • Download URL: albucore-0.0.38.tar.gz
  • Upload date:
  • Size: 27.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for albucore-0.0.38.tar.gz
Algorithm Hash digest
SHA256 1f11c51e5fe7673ea197fcdfc30886f623f1f48a4175b98447cdf6ea39bcf7b7
MD5 f02d3b2072368f43f0ae3f670c83a6f6
BLAKE2b-256 7df9818d02ff3f86cbc9e5ec04c350adb629dbb6685d17dd75c3d22601bd4997

See more details on using hashes here.

File details

Details for the file albucore-0.0.38-py3-none-any.whl.

File metadata

  • Download URL: albucore-0.0.38-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for albucore-0.0.38-py3-none-any.whl
Algorithm Hash digest
SHA256 c8b729e9e295bdc1027fe4b43ecc1883e6881b7c3277a52f4f52136f7a437cd5
MD5 0a96f1f7928e5fb82732fea5ef15a5d7
BLAKE2b-256 eaaeaf44a9355ba58023154792c426ea78dbb3bba475eb54191c644119af486d

See more details on using hashes here.

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