Прочитать и отобразить изображение в виде пиксельной матрицы - появляется ошибка - PullRequest
0 голосов
/ 19 октября 2018

Это мой код для чтения изображения и отображения в виде пиксельной матрицы

    PIL import Image
    import os.path

    filename = os.path.join('seaturtle.jpg')
    img = Image.open('seaturtle.jpg')
    width, height = img.size
    print ("Dimensions:", img.size, "Total pixels:", width * height)
    x = img.size #Here it is 1000,480
    y = width*height
    import cv2
    cv2.__version__
    import numpy as np
    def get_num_pixels(filepath):
        width, height = Image.open(open('seaturtle.jpg')).size
        return width*height
    img = Image.open('seaturtle.jpg')
    arr = np.array(img) # 640x480x4 array
    arr[x] # 4-vector, just like above]
    print(*arr, sep=", ")

Но я получаю эту ошибку

IndexError: index 1000 is out of bounds for axis 0 with size 480

Как ее исправить?

...