Albumentations is python library that simplifies the process of augmenting images for computer vision tasks.

Two things I liked about it are that it has a lot of different data augmentations that can be applied to images. And its easy to use the library.

Its quite powerful since it also supports creating your own transformations.

The full API reference is here. It doesnt have an option to search which is not good. But we'll take what we can get. Atleast something is there. Just use chatGPT for this.

A simple example to use Albumentations would be as below.

import albumentations as A
import cv2

transform = A.Compose([
    A.HueSaturationValue(p=0.5),
    A.RandomBrightnessContrast(p=0.5),
    A.RandomGamma(p=0.5),
    A.Flip(p=0.5),
    A.Rotate(p=0.5),
    A.MultiplicativeNoise(multiplier=[0.5, 1.5], elementwise=True, per_channel=True, p=0.5),
    A.ShiftScaleRotate(shift_limit=0.0625, rotate_limit=45, p=0.5),
    A.Transpose(p=0.5)
])

input_image = cv2.imread('input_image.jpg')
input_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB)
transformed_image = transform(image=input_image)["image"]
cv2.imwrite('input_image_transformed.jpg', cv2.cvtColor(transformed_image, cv2.COLOR_RGB2BGR))

Above we define 8 different image transformations which would be applied sequentially. But there's a twist. We specify a transformation probability and hence every time we use this data transform, the transformations are stochastic.