Introduction
imgaug is a Python library that helps you augment images for training machine learning models. It provides a wide range of geometric, color, and noise transformations that also correctly transform associated annotations like bounding boxes and segmentation masks.
What imgaug Does
- Applies 60+ augmentation techniques including affine transforms, blur, contrast, and weather effects
- Transforms bounding boxes, polygons, keypoints, and segmentation maps alongside images
- Supports stochastic pipelines with per-image randomization
- Handles batches of images efficiently with NumPy vectorization
- Integrates with Keras, PyTorch DataLoaders, and other training frameworks
Architecture Overview
imgaug defines augmenters as composable objects organized in a tree structure. A Sequential or SomeOf container wraps individual augmenters. At runtime, each augmenter samples its random parameters once per batch or per image, applies the transform to pixel data, and propagates the same spatial transform to any annotation objects through a shared coordinate mapping.
Self-Hosting & Configuration
- Install:
pip install imgaug(requires NumPy, scipy, scikit-image, Pillow) - Define augmentation pipelines using
iaa.Sequential,iaa.SomeOf, oriaa.OneOf - Control randomness with deterministic mode:
aug_det = aug.to_deterministic() - Tune intensity with stochastic parameters:
iaa.GaussianBlur(sigma=(0.0, 3.0)) - Visualize augmentations with built-in
imgaug.imshow()and grid drawing
Key Features
- Consistent coordinate-aware augmentation for detection and segmentation tasks
- Stochastic parameters let you define value ranges and distributions per augmenter
- Deterministic mode ensures identical transforms across image-annotation pairs
- Built-in debug visualization and augmentation grid generation
- Supports conditional augmentation with probability controls per step
Comparison with Similar Tools
- Albumentations — faster pixel-level transforms using OpenCV; imgaug offers richer annotation support
- torchvision.transforms — tightly coupled with PyTorch but fewer augmentation types
- Augmentor — simpler API for basic pipelines; imgaug supports complex stochastic graphs
- Kornia — GPU-accelerated differentiable augmentations; imgaug is CPU-based and NumPy-native
FAQ
Q: Is imgaug still maintained? A: The library is stable but development has slowed. It remains widely used in production pipelines.
Q: Can I use imgaug with PyTorch DataLoaders?
A: Yes. Apply augmentations inside your Dataset class's __getitem__ method.
Q: Does imgaug support video augmentation? A: Not directly. Apply the same deterministic augmenter to each frame for temporal consistency.
Q: How does performance compare to Albumentations? A: Albumentations is generally faster for pixel transforms. imgaug's strength is complex annotation-aware pipelines.