Center Crop
Augment your data by cropping the central part
Data augmentation tool that allows you to crop your samples to a specified height and width with certain probability.
Since it is center crop, the central part of the image is cropped.

Parameters

Height

It defines the height of the newly cropped image.

Width

It defines the width of the newly cropped image.

Probability

It is the probability of the application of this transform.
โ€‹
Original Image. (Source: http://hypertextbook.com/chaos/eyecandy)
Image After Center Crop

Code Implementation

1
import albumentations as albu
2
from PIL import Image
3
import numpy as np
4
โ€‹
5
โ€‹
6
transform =albu.CenterCrop(200,200,p=0.5)#set height, width, and probability
7
โ€‹
8
โ€‹
9
image = np.array(Image.open('/some/image/file/path'))
10
image = transform(image=image)['image']
11
โ€‹
12
โ€‹
13
# Now the image is cropped and ready to be accepted by the model
14
โ€‹
Copied!

Further Resources

Last modified 3mo ago