根据像素矩阵读取和显示图像-出现错误

时间:2018-10-19 12:30:48

标签: python image image-processing pixel spyder

这是我的代码,用于读取图像并按照像素矩阵显示

    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

我该如何解决?

0 个答案:

没有答案