Error in PIL, image index out of range, python

2

Very good, I would like you to clarify a doubt. Creating a function that from a "L" image creates a matrix with the values of its pixels, it returns this:

  

return self.im.getpixel (xy), IndexError: image index out of range

If someone can answer me, I would be very grateful, because I have hours and hours and hours with this.

The code:

from PIL import Image

def datalize(img):
    x, y = img.size
    datrix = []

    for e in xrange(x):
        datrix.append([])
            for m in xrange(y):
                delta = img.getpixel((x,y))
                delta = int(delta)
                datrix[e].append(delta)
    return datrix

Thanks in advance

    
asked by Phazoning 21.09.2016 в 22:44
source

1 answer

1

On the line where you get delta for the first time you're using (x,y) and I think it should be (e,m) .

If your image has, for example, 1000 x 500 pixels (x = 1000, y = 500) when you index, in Python, the indexing begins with 0 and, therefore, you could index the x from 0 to 999 and the y from 0 to 499, when using x=1000 e y=500 ( x e y you get%% of%, I use some hypothetical values) you are indexing and that is why returns img.size

    
answered by 21.09.2016 / 23:10
source