imgaug is a Python library for image augmentation in machine learning that provides a highly flexible, stochastic API for building complex augmentation pipelines — enabling fine-grained control over augmentation parameters through stochastic expressions (rotate between -10° and +10° with truncated normal distribution), deterministic mode for applying identical transforms to images and their annotations (masks, bounding boxes, keypoints), and a rich set of 60+ augmentations with compositional operators (Sequential, SomeOf, OneOf) for building sophisticated augmentation strategies.
What Is imgaug?
- Definition: An open-source Python library (pip install imgaug) for augmenting images in machine learning experiments — providing a composable, stochastic pipeline for geometric, color, noise, weather, and artistic augmentations with support for bounding boxes, segmentation maps, heatmaps, and keypoints.
- Key Strength: Stochastic parameters — instead of "rotate by exactly 10°", you specify "rotate by a value drawn from Normal(0, 5°) clipped to [-15°, 15°]", giving fine-grained control over the augmentation distribution.
- Status Note: imgaug's development has slowed since ~2021. Albumentations is now the more actively maintained and faster alternative. However, imgaug's stochastic parameter API remains more flexible for complex augmentation distributions.
Core Usage
import imgaug.augmenters as iaa
seq = iaa.Sequential([
iaa.Fliplr(0.5), # 50% chance horizontal flip
iaa.GaussianBlur(sigma=(0, 1.0)), # Blur with sigma 0-1
iaa.Affine(
rotate=(-15, 15), # Rotate -15 to +15 degrees
scale=(0.8, 1.2) # Scale 80% to 120%
),
iaa.AdditiveGaussianNoise(scale=(0, 0.05*255))
])
images_aug = seq(images=images)
Composition Operators
| Operator | Behavior | Use Case |
|---|---|---|
| Sequential | Apply all transforms in order | Standard pipeline |
| SomeOf((2, 4), [...]) | Randomly select 2-4 from the list | Variable augmentation strength |
| OneOf([...]) | Apply exactly one from the list | Mutually exclusive transforms |
| Sometimes(0.5, ...) | Apply with 50% probability | Optional augmentations |
Stochastic Parameters (imgaug's Unique Feature)
# Normal distribution for rotation
iaa.Affine(rotate=iap.Normal(0, 5))
# Truncated normal (clipped to range)
iaa.Affine(rotate=iap.TruncatedNormal(0, 5, low=-15, high=15))
# Different distributions for different parameters
iaa.Affine(
rotate=iap.Normal(0, 10), # Rotation: normal distribution
scale=iap.Uniform(0.8, 1.2), # Scale: uniform distribution
shear=iap.Laplace(0, 3) # Shear: Laplace distribution
)
imgaug vs Albumentations
| Feature | imgaug | Albumentations |
|---|---|---|
| Speed | Moderate | 2-5× faster (OpenCV optimized) |
| Stochastic params | Full distribution control | Basic probability only |
| Development | Slowed (~2021) | Active development |
| Transform count | 60+ | 70+ |
| Deterministic mode | Built-in | Built-in |
| Box/mask support | Good | Excellent (native) |
| PyTorch integration | Manual | ToTensorV2 included |
| Community | Moderate | Large (Kaggle standard) |
When to Use imgaug
| Use imgaug | Use Albumentations |
|---|---|
| Need fine-grained stochastic parameter control | Need maximum speed |
| Existing pipeline already uses imgaug | Starting a new project |
| Complex augmentation distributions (truncated normal, Laplace) | Standard augmentation needs |
| Research requiring precise control over augmentation statistics | Production deployment or competition |
imgaug is the flexible, research-oriented image augmentation library — providing unmatched control over augmentation parameter distributions through stochastic expressions, with a rich compositional API for building complex pipelines, while Albumentations has become the faster and more actively maintained alternative for production and competition use cases.
Explore 500+ Semiconductor & AI Topics
From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.