PIL IndexError:图像索引超出范围

时间:2018-01-09 20:12:34

标签: python python-imaging-library

我试图用Python制作一个chromakey程序。我的测试程序应该确定图像中的绿色。如果找到绿色,则将某个值设置为True。测试图像是4x4图像,没有透明度。

import PIL
from PIL import Image

green_num = False
testpic = Image.open("test.png")
width, height = testpic.size
pix = testpic.load()


def coloradd():
    global colorlist
    colorlist = 0
    if green_value/(2/3) < red_value or blue_value:
        colorlist += 1


def colorscan():
    current_x = 0
    current_y = 0
    while current_y <= height:
        global red_value, green_value, blue_value
        red_value, green_value, blue_value, transparency = pix[current_x, current_y]
        coloradd()
        current_x += 1
        if current_x < width:
            current_y += 1


colorscan()
print(colorlist)

到目前为止,我一直遇到这个错误。

Traceback (most recent call last):
  File "C:/Users/shawnmcgp/PycharmProjects/untitled/chromakey.py", line 29, in <module>
    colorscan()
  File "C:/Users/shawnmcgp/PycharmProjects/untitled/chromakey.py", line 22, in colorscan
    red_value, green_value, blue_value, transparency = pix[current_x, current_y]
IndexError: image index out of range

0 个答案:

没有答案