Random Sized Crop
Crop your training data to any size within a bound
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.

Parameters

Height

Sets the height of the desired cropped image in pixels.

Width

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

1
import albumentations as albu
2
from PIL import Image
3
โ€‹
4
โ€‹
5
transform =albu.RandomSizedCrop([1500,2000],100,100,1.0,cv2.INTER_NEAREST,1)
6
augmented_image = transform(image=figure)['image']
7
โ€‹
8
# we have our required cropped image in augmented_image.
9
โ€‹
10
# the first argument defines the crop size limits.
11
# second and third are the height and width of the image after crop and resize
12
# fourth is the aspect ratio of crop
13
# fifth is the interpolation technique, and the last is the probability of the
14
transform.
Copied!

Further Resources

Last modified 2mo ago