gpt4 book ai didi

python - 无法在 PIL 中的 16 位 TIF 上应用图像滤镜

转载 作者:太空狗 更新时间:2023-10-30 01:45:09 25 4
gpt4 key购买 nike

我尝试使用 python 的 PIL 应用图像过滤器.代码很简单:

im = Image.open(fnImage)
im = im.filter(ImageFilter.BLUR)

此代码在 PNG、JPG 和 8 位 TIF 上按预期工作。但是,当我尝试将此代码应用于 16 位 TIF 时,出现以下错误

ValueError: image has wrong mode

请注意,PIL 能够毫无怨言地加载、调整和保存 16 位 TIF,因此我认为此问题与过滤器有关。然而,ImageFilter documentation只字不提 16 位支持

有什么办法可以解决吗?

最佳答案

您的 TIFF 图像的模式很可能是“I;16”。在当前版本的 ImageFilter 中,内核只能应用于 “L”和“RGB”图像(参见 ImageFilter.py 的源代码)

首先尝试转换为另一种模式:

im.convert('L')

如果失败,尝试:

im.mode = 'I'
im = im.point(lambda i:i*(1./256)).convert('L').filter(ImageFilter.BLUR)

备注:可能与Python and 16 Bit Tiff重复

关于python - 无法在 PIL 中的 16 位 TIF 上应用图像滤镜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8062564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com