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 Longest max size augmentation;

  • Check out its parameters;

  • See how Longest max size affects an image;

  • And check out how to work with Longest max size using Python through the Albumentations library.

Let's jump in.

To define the term, Longest max size is a data augmentation technique that fixes the maximum possible length of the image's longest side.

Note that the image's aspect ratio is preserved, and hence the other side of the image will also be proportionally scaled after the Longest max size application.
  • Maximum size of longest side - sets the desired maximal length of the image in pixels. The values can vary from 256 to 3000.

You can add several values to this parameter. In this case, each image's maximum length will be chosen randomly from the specified values. You might use this option to make your dataset more diversified.
Original image
Image after Longest max size (maximum size 256 and Linear interpolation) was applied
      import albumentations as albu
from PIL import Image
import numpy as np

transform = albu.LongestMaxSize(max_size=500, interpolation=1, p=1)
#default interpolation is INTER_LINEAR

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

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

Boost model performance quickly with AI-powered labeling and 100% QA.

Learn more
Last modified