преобразовать цветное изображение в оттенки серого в python, используя numpy и PIL, но получаю эту ошибку: - PullRequest
0 голосов
/ 29 апреля 2018

images [x, y] = math.ceil (0.2989 * r + 0.5870 * g + 0.1140 * b)

IndexError: индекс 302 выходит за пределы оси 0 с размером 302

# Загруженные изображения - это множество изображений, переданных из другого класса:

def preprocess(loadedImages):
    i=0
    newloadedImages = []

    for img in loadedImages: #looping for each images passed
        w, h = img.size
        print("Height and width of image is: " + str(w) + " " + str(h) + "\n")
        images = np.zeros((h,w ), np.uint8)
        j=0
        for width in range(1, w ): #looping for the width size
            for height in range(1, h): #looping for the height size
                j=j+1
                coordiante = x, y = (width, height)
                r, g, b = img.getpixel(coordiante)
                print(str(r) + " " + str(g) + " " + str(b) + "\n")
                print("image number: "+str(i)+" iterations: "+str(j)+"\n")
                images[x, y] = math.ceil(0.2989 * r + 0.5870 * g + 0.1140 * b)
            newImage = Image.fromarray(np.uint8(images))
            newloadedImages.append(newImage)
         i=i+1
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...