【发布时间】:2021-08-02 02:30:23
【问题描述】:
我试图找出图像的某个像素是否具有更多的红绿或蓝值。我在下面尝试了这段代码:
im = Image.open("image.png")
x = 32
y = 32
pixel = im.load()
rgb = pixel[x,y]
rgb = int(rgb)
if rgb[0] > rgb[1,2]:
print("Red")
elif rgb[1] > rgb[0,2]:
print("Green")
elif rgb[2] > rgb[0,1]:
print("Blue")
但它给了我这个错误:
File "d:\path\app.py", line 11, in <module>
rgb = int(rgb)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
请让我知道我做错了什么,或者是否有更好的方法!
谢谢
-丹尼尔
【问题讨论】:
-
也许你的意思是
pixel((x,y)) -
int()不接受元组参数。如果 rgb 是一个元组,不要管它。然后使用` if rgb[0] > rgb[1] and rgb[0]>rgb[2]` etc... -
尝试 rgb = [int(i) for i in rgb] 将 rgb 列表转换为整数
标签: python image python-imaging-library rgb