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 Shift Scale Rotate augmentation;
Check out its parameters;
See how Shift Scale Rotate affects an image;
And check out how to work with Shift Scale Rotate using Python through the Albumentations library.
Let’s jump in.
To define the term, Shift Scale Rotate is a data augmentation technique used to randomly apply affine transformations such as shift, scale, and rotate.
It is worth mentioning that Shift Scale 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 Shift Scale 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.
The shift factor ranges between -1 and 1. The negative shift factor shifts the pixels leftwards in the horizontal direction and upwards in the vertical direction. The positive shift factor shifts the pixels rightwards in the horizontal direction and downwards in the vertical direction. The magnitudes define the shifting degree.
The scale factor should be between -1 and 1. A negative scale factor zooms out the image, whereas a positive scale factor zooms in the image. The magnitude defines the zooming degree.
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.
- Interpolation - specifies the interpolation algorithm:
- Extrapolation - specifies the extrapolation algorithm:
- Padding value if border mode is Constant and Padding value if order mode is Constant applied or masks - please check out the general Extrapolation page to learn more.
import albumentations as albu
from PIL import Image
import numpy as np
transform = albu.augmentations.geometric.transforms.ShiftScaleRotate(shift_limit = 0.0625, scale_limit = 0.1, rotate_limit = 45)
image = np.array(Image.open('/some/random/image.png'))
augmented_image = transform(image=image)['image']