Rotate

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 Rotate augmentation;
  • Check out its parameters;
  • See how Rotate affects an image;
  • And check out how to work with Rotate using Python through the Albumentations library.

Let’s jump in.

Rotate explained

To define the term, Rotate is a data augmentation technique used to randomly rotate an image clockwise or counter-clockwise by a certain number of degrees. As the transformation result, you will get an updated image with the changed position of the objects in the frame.

It is worth mentioning that Rotate requires updating labels (bounding boxes, polygons, etc.) to correspond to an object after the transformation is applied. Fortunately, Hasty has your back and does all the necessary things for you to focus on designing your solution without bothering about routine.

Using Rotate helps Data Scientists increase the variety of points of view on an object in the training set. This approach creates the needed diversity without the need to find and label more data.

Parameters

  • Probability of applying transform - defines the likelihood of applying Rotate to an image;
  • Range from which a random angle is picked - as the name suggests, this parameter specifies a certain range from which a random angle (in degrees) is picked and used to rotate an image.
A negative value specifies a clockwise direction, whereas a positive angle is for a counter-clockwise direction. For example, if your range is [-90, -45], an image will be rotated in the clockwise direction.

Rotate visualized

Original image
Image after Rotate is applied
Image after Rotate is applied

Code implementation

        import albumentations as albu
from PIL import Image
import numpy as np


transform = albu.RandomRotation(degrees=(-90,90))
image = np.array(Image.open('/some/random/image.png'))
augmented_image = transform(image=image)['image']

# We have the rotated image in augmented_image.
    

Learn more about other augmentations …

Last updated on Sep 23, 2022

Get to production reliably.

Hasty is a unified agile ML platform for your entire Vision AI pipeline — with minimal integration effort for you.