Resize your training data to bring diversity to your dataset

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


Height: Allows you to adjust the height of the image on pixels.

Width: Allows you to adjust the width of the image on pixels.

Probability: This gives you the probability of each of the training datasets 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 the case when the image is drastically enlarged, then one can opt for the cubic or Lanczos algorithm

Code Implementation

import cv2
src = cv2.imread('D:/cv2-resize-image-original.png', cv2.IMREAD_UNCHANGED)
# set a new width in pixels
new_width = 300
# dsize
dsize = (new_width, src.shape[0])
# resize image
output = cv2.resize(src, dsize, interpolation = cv2.INTER_AREA)