【发布时间】:2023-04-02 22:14:01
【问题描述】:
当我运行我的 PIL 代码时,它有这个错误:
from PIL import Image,ImageDraw, ImageColor, ImageChops
# Load images
im1 = Image.open('im1.png')
im2 = Image.open('im2.png')
# Flood fill white edges of image 2 with black
seed = (0, 0)
black = ImageColor.getrgb("black")
ImageDraw.floodfill(im2, seed, black, thresh=127)
# Now select lighter pixel of image1 and image2 at each pixel location and
result = ImageChops.lighter(im1, im2)
result.save('result.png')
错误在我的图像处理中:
Traceback (most recent call last):
File "C:\Users\Martin
Ma\Desktop\test\36\light_3_global\close_open\gray\main.py", line 96, in <module>
ImageDraw.floodfill(im2, seed, black, thresh=127)
File "E:\python\lib\site-packages\PIL\ImageDraw.py", line 346, in floodfill
if _color_diff(value, background) <= thresh:
File "E:\python\lib\site-packages\PIL\ImageDraw.py", line 386, in _color_diff
return abs(rgb1[0]-rgb2[0]) + abs(rgb1[1]-rgb2[1]) + abs(rgb1[2]-rgb2[2])
TypeError: 'int' object is not subscriptable
我该如何解决?非常感谢!
【问题讨论】:
-
检查您的输入...
-
我认为您需要创建一个 ImageDraw 绘图上下文对象。见pillow.readthedocs.io/en/5.1.x/reference/…
-
请做一些最小的调试。复制给你的代码以回答一个以最少的努力提出的问题并要求人们为你修复它并不是很酷:stackoverflow.com/a/52504053/2988730
-
floodfill需要什么参数,你提供了什么?似乎不匹配。