If you have ever worked on a Computer Vision project, you might know that using augmentations to diversify the dataset is the best practice. On this page, we will:

  • Сover the Horizontal Flip augmentation;
  • Check out its parameters;
  • See how Horizontal Flip affects an image;
  • And check out how to work with Horizontal Flip using Python through the Albumentations library.

Let’s jump in.

As you might know, every image can be viewed as a matrix of pixels, with each pixel containing some specific information, for example, color or brightness.

Pixel matrix representation of an image
Source

To define the term, Horizontal Flip is a data augmentation technique that takes both rows and columns of such a matrix and flips them horizontally. As a result, you will get an image flipped horizontally along the y-axis.

  • Probability of applying transform - defines the likelihood of applying Horizontal Flip to an image.
If a large fraction of training images needs to be flipped, set a high probability.

In the real world, people regularly confuse Horizontal and Vertical Flip as they feel alike. Still, there is a clear-cut difference:

  • Horizontal Flip flips an image along the y-axis;
  • Vertical Flip flips an image along the x-axis.
Horizontal Flip Vs. Vertical Flip
Source

That is it. Keep this info in mind, and you will never find yourself stuck on a thought of which augmentation to choose.

For a deeper dive please check out our Vertical Flip page.
Original image (before Horizontal Flip)
Source
Image after Horizontal Flip was applied
Source
python
      import albumentations as albu
from PIL import Image
import numpy as np

transform =albu.HorizontalFlip(p=0.5)
image = np.array(Image.open('/some/random/image.png'))
augmented_image = transform(image=image)['image']

# we have our required flipped image in augmented_image.
    

Boost model performance quickly with AI-powered labeling and 100% QA.

Learn more
Last modified