2

I have a dataset containing images with variable widths and heights. I want to resize them to a fixed size, e.g., 128 x 128 for my model. I can resize using PIL like

Image.resize(size, Image.ANTIALIAS)

OR

Image.thumbnail(size, Image.ANTIALIAS)

The problem is that when the image width or height is smaller than 128px, these approaches dont resize the image to the desired size as they need to maintain the aspect ratio. I observed the same behavior with ImageOps.contain().

Is there a better way to resize the images to a fixed dimension while maintaining the aspect ratio using python or pytorch (transforms.Resize() in this case squashes the output)?

Ammar Ul Hassan
  • 826
  • 1
  • 18
  • 48

0 Answers0