Resize

Resize your training data to bring diversity to your dataset

The data augmentation tool allows you to resize your training images. This transformation yields a synthetic image which is helpful in creating diverse training sets.

Parameters

Height

Adjusts the height of the image in pixels.

Width

Adjusts the width of the image in pixels.

Probability

This gives you the probability of each of the training images to be resized. For example, if there are 100 training images and the probability is set to 0.5, then the expected number (not exactly, but expected) of resized images is 50.

Resizing Algorithms

  • Linear Interpolation

  • Cubic Interpolation

  • Nearest Pixel

  • Area

  • Lanczos algorithm

Using the Nearest Pixel or the Area option for enlarging the images can produce pixelated borders. To obtain smooth borders after enlarging the image, one can use any of the remaining three. If choosing linear interpolation still produces pixelated borders, which can happen in cases where the image is drastically enlarged, then you can opt for the Cubic or Lanczos algorithm.

Code Implementation

import albumentations as albu
from PIL import Image
import numpy as np
transform =albu.Resize(224, 224)
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

Further Resources