Random Sized Crop

This data augmentation feature allows you to crop an image to any size within a certain specified bound. Like all other augmentation, this creates synthetic data for training.



Sets the height of the desired cropped image in pixels.


Sets the width of the desired cropped image in pixels.

Maximum and Minimum height

Sets the range of size to which the image is cropped.

First, the image is cropped to any size within the given bounds. Then, it is resized to the given "Height" and "Width" parameters.

For example, if the bound is set from 1500 to 2000, and the height and width are set to 200, then a size anywhere between 1500 to 2000 is cropped, and this image is then resized to 200x200 pixels. This is why some of the objects in the image might look distorted.

Code Implementation

import albumentations as albu
from PIL import Image

transform =albu.RandomSizedCrop([1500,2000],100,100,1.0,cv2.INTER_NEAREST,1)
augmented_image = transform(image=figure)['image']

# we have our required cropped image in augmented_image.

# the first argument defines the crop size limits.
# second and third are the height and width of the image after crop and resize
# fourth is the aspect ratio of crop
# fifth is the interpolation technique, and the last is the probability of the

Further Resources

Last updated on Jun 01, 2022

Get AI confident. Start using Hasty today.

Automate 90% of the work, reduce your time to deployment by 40%, and replace your whole ML software stack with our platform.