我试着用PIL和python制作3D图像。但是我找到了AssertionError,上面写着“assert image.mode == "L"”,在包含“(red_img = ImageOps.colorize(right_img_developed,(0, 0, 0), (255, 0, 0)))和cyan_img = ImageOps.colorize(left_img_developed,(0, 0, 0), (0, 255, 255))”的那条线上,我试着搜索错误,但没有得到任何答案。我还查看了文档,但找不到任何有用的帮助。谢谢。:这是我的代码:
import io, re, requests
from PIL import Image, ImageOps, ImageEnhance
imgpth ='path/image.jpg'
right_img = Image.open(imgpth)
right_img_resized = right_img.resize((400, 400))
right_img_developed = right_img_resized.transform((400, 300), Image.QUAD, data =(0, 0, 100, 400, 300, 400, 400, 0), resample=Image.BILINEAR)
left_img_url = re.sub('FRB', 'FLB', imgpth)
left_img = Image.open(left_img_url)
left_img_resized = left_img.resize((400, 400))
left_img_developed = left_img_resized.transform((400, 300), Image.QUAD, data =(0, 0, 100, 400, 300, 400, 400, 0), resample=Image.BILINEAR)
red_img = ImageOps.colorize(right_img_developed,(0, 0, 0), (255, 0, 0))
cyan_img = ImageOps.colorize(left_img_developed,(0, 0, 0), (0, 255, 255))
blend = Image.blend(red_img, cyan_img, 0.5)
red_img.show()
cyan_img.show()
blend.show()发布于 2021-04-10 12:59:50
函数ImageOps.colorize需要一个灰度图像作为输入,并对其应用颜色刻度。这就是模式"L“的意思(L =L,亮度=灰度)。
如果正在加载的图像以RGB(A)格式存储,则可以将其转换为灰度,如下所示:
img = Image.open("image.jpg").convert("L")https://stackoverflow.com/questions/67033086
复制相似问题