使用Python枕头在Google Colab上调整图像大小

时间:2020-01-18 13:26:02

标签: python-3.x python-imaging-library google-colaboratory image-resizing

我在我的google驱动器中有我的ipynb和一个名为PRimage的文件夹(包含100多个图像),并且该驱动器已经挂载在/ content / drive中。我的图像按顺序排列。 1_1.jpg,1_2.jpg等。我正在尝试使用for循环来调整所有图像的大小,例如:

from google.colab import drive
drive.mount('/content/drive')

from os import listdir
from matplotlib import image
from PIL import Image

loaded_images = list()
for filename in listdir('/content/drive/My Drive/PRimage'):
  img_data = image.imread('/content/drive/My Drive/PRimage/'+ filename)
  loaded_images.append(img_data)
  print('> loaded %s %s' % (filename, img_data.shape))

def resize():
    files = listdir('/content/drive/My Drive/PRimage')
    for item in files:
            image = Image.open(item)
            image.thumbnail((64,64))
            print(image.size)

resize()

但是,我收到此错误消息:

enter image description here

0 个答案:

没有答案