How to properly resize input images for transfer learning

I have to resize some images of different size to 224x224 before they can be passed as input for VGG19, and then apply transfer learning.

I have tried these methods: add patches, take a square of 224x224 from the images' center, automatically adjust height and width.

I would like to know, if there is one, which is the best method for resizing these images.

This can be accomplished using the PIL library in Python.

One thing to note - if you are resizing the images to 224x224, you might want to keep the proportion of your image, e.g. if the height and width is significantly different, then you might lose perspective by resizing in this way.

If proportion is not an issue, you can resize as follows:

from PIL import Image
baseheight = 224
img = Image.open('image.jpg')
width = 224
img = img.resize((width, baseheight), Image.ANTIALIAS)
img.save('resizedimage.jpg')


That said, if you wanted to keep the same proportions as the original image and only wanted to set height to 224 for instance while keeping a proportional width, you could also use PIL as follows:

from PIL import Image
baseheight = 224
img = Image.open('image.jpg')
hpercent = (baseheight / float(img.size[1]))
width = int((float(img.size[0]) * float(hpercent)))
img = img.resize((width, baseheight), Image.ANTIALIAS)
img.save('resizedimage.jpg')