0

I am required to access all images in a folder and store it in a matrix using python. Here is my code.

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

but I am getting the error: AttributeError: __getitem__

from the line: images[:, x] = img[:]

4

0 回答 0