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

Let’s jump in.

Center Crop explained

To define the term, Center Crop is a data augmentation technique that helps researchers to crop images to a specified height and width with a certain probability.

The key difference between Random Crop and Center Crop is that the latter crops the central part of an image.

Parameters

  • Height - defines the height of the newly cropped image in pixels;
  • Width - defines the width of the newly cropped image in pixels;
  • Probability - the probability that the transformation will be applied to an image.

Center Crop visualized

Original image
Image after Center Crop was applied (height = 128, width = 300, probability = 1)

Code Implementation

        import albumentations as albu
from PIL import Image
import numpy as np

transform =albu.CenterCrop(200,200,p=0.5)#set height, width, and probability

image = np.array(Image.open('/some/image/file/path'))
image = transform(image=image)['image']

# Now the image is cropped and ready to be accepted by the model
    

Learn more about other augmentations …

Last updated on Sep 24, 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.