imgaug

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

OperatorBehaviorUse Case
SequentialApply all transforms in orderStandard pipeline
SomeOf((2, 4), [...])Randomly select 2-4 from the listVariable augmentation strength
OneOf([...])Apply exactly one from the listMutually exclusive transforms
Sometimes(0.5, ...)Apply with 50% probabilityOptional 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

FeatureimgaugAlbumentations
SpeedModerate2-5× faster (OpenCV optimized)
Stochastic paramsFull distribution controlBasic probability only
DevelopmentSlowed (~2021)Active development
Transform count60+70+
Deterministic modeBuilt-inBuilt-in
Box/mask supportGoodExcellent (native)
PyTorch integrationManualToTensorV2 included
CommunityModerateLarge (Kaggle standard)

When to Use imgaug

Use imgaugUse Albumentations
Need fine-grained stochastic parameter controlNeed maximum speed
Existing pipeline already uses imgaugStarting a new project
Complex augmentation distributions (truncated normal, Laplace)Standard augmentation needs
Research requiring precise control over augmentation statisticsProduction 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.

Go deeper with CFSGPT

Get AI-powered deep-dives, save terms, and run advanced simulations — free account.

Create Free Account