Python - AttributeError:__ getitem__

时间:2013-04-07 12:58:13

标签: python image-processing numpy

我需要访问文件夹中的所有图像并使用python将其存储在矩阵中。这是我的代码。

import Image
import os
from PIL import Image
from numpy import *
import numpy as np


#import images
dirname = "C:\\Users\\Karim\\Downloads\\att_faces\\New folder"

#get number of images and dimentions
path, dirs, files = os.walk(dirname).next()
num_images = len(files)
image_file = "C:\\Users\\Karim\\Downloads\\att_faces\\New folder\\2.pgm"
im = Image.open(image_file)
width, height = im.size



images = []

for x in xrange(1, num_images):
    filename = os.listdir(dirname)[x]
    filepath = os.path.join(dirname, filename)
    img = Image.open(filepath)
    img = im.convert('L')
    images[:, x] = img[:]

print images

但我收到错误:AttributeError: __getitem__

行:images[:, x] = img[:]

0 个答案:

没有答案