Random Crop

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

Let's jump in.

Random Crop explained

To define the term, Random Crop is a data augmentation technique that helps researchers to crop the images into a particular dimension, creating synthetic data. The cropping could result in any patch of the image and is therefore called "Random Crop."

Make sure that the original image size is larger than the requested crop size.

Parameters

  • Height - sets the height of the desired cropped image in pixels;
  • Width - sets the width of the desired cropped image in pixels.

Random Crop visualized

Original image
Image after Random Crop was applied (height = 154, width = 17)

Code Implementation

        import albumentations as albu
from PIL import Image

transform = albu.RandomCrop(200,200)
augmented_image = transform(image=figure)['image']

# We have our required cropped image in augmented_image.
    

Learn more about other augmentations …

Last updated on Sep 24, 2022

Removing the risk from vision AI.

Only 13% of vision AI projects make it to production, with Hasty we boost that number to 100%.