3

What does keras.preprocessing.image.load_img do during image resizing?

In the following statement, target size is set to 128x128.

image1 = img_to_array(image.load_img(img, target_size=(128,128))) / 255

What if I load 100x100 size image?

Will it leave the image as it is or will it zoom to 128x128 size?

Emma
  • 27,428
  • 11
  • 44
  • 69
PCG
  • 2,049
  • 5
  • 24
  • 42

1 Answers1

2

It will actually resize it to the target size!

If the image size is smaller than the target size it will be stretched to fit the desired size.

  • does it maintain the aspect ratio? – Lahiru Karunaratne Jul 30 '19 at 07:36
  • 1
    It depends to the target size, so it will preserve when they share the same aspect ratio. – Jeferson Silva Jul 31 '19 at 12:15
  • @LahiruKarunaratne No, it does not care about the aspect ratio. It just resizes to the desired size. But I am wondering how exactly. Can anyone in the group answer it? So if it wants to stretch the image when the actual size is less than the desired size, does it do some kind of pixel duplication? – Aashish Chaubey Jun 11 '21 at 04:31