Exercise: Using the Albumentations Library for Augmentations

Playground

Using an image, we will implement a technique to produce two variations of the image by adjusting its brightness, contrast, saturation, and hue.

Functions to learn before coding

  • The Compose function: It is used to combine multiple image transformation operations. Each transformation is applied sequentially in the order it appears in the list.

  • The HorizontalFlip function: This is a transformation that flips an image horizontally (like a mirror effect). Here are its parameters:

    • p: It is the probability of applying the augmentation. If p=1, it will always flip the image, while if p=0, it will never flip the image. A p=0.5 means there’s a 50% chance to apply the flip.

  • The augmentation probability (p) function: For many transformations in Albumentations, there's a p parameter that dictates the probability of applying that augmentation. It allows for randomization of transformations, which, in turn, increases the variety of augmented images.

  • The data augmentation pipeline: It's common to apply a series of augmentations to an image rather than just one. This helps create a diverse set of augmented images from a single source image. Using Compose, one can define a sequence of transformations.

  • Spatial augmentations and color augmentations: In image augmentations, transformations can be categorized broadly into spatial and color augmentations.

    • Spatial augmentations: It modifies the position or structure of the objects within an image, e.g., flips, rotations, and cropping.

    • Color augmentations: It modifies the color properties of an image without changing its structure, e.g., brightness, contrast, and hue adjustments.

Steps

We will experiment with different values for brightness, contrast, and hue to visualize their effect on the original image.

Get hands-on with 1200+ tech skills courses.