Python 如何使用枕头创建和保存灰度图像的gif?
运行此操作时,我得到一个属性错误。 此代码适用于另一个RGB数据集。 Python3.6,windows10 代码: _gif的Python 如何使用枕头创建和保存灰度图像的gif?,python,python-imaging-library,gif,Python,Python Imaging Library,Gif,运行此操作时,我得到一个属性错误。 此代码适用于另一个RGB数据集。 Python3.6,windows10 代码: _gif的如下所示: [<PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A07CF28>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0EC7F0>, <PIL.Png
如下所示:
[<PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A07CF28>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0EC7F0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0F08D0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0F0BE0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC080>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120
at 0x1FE2A0FC0F0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC160>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC1D0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC240>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC2B0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC320>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC390>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC400>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC470>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC4E0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC550>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC5C0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC630>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC6A0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC710>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC780>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC7F0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC860>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC8D0>, <PIL.PngImagePlugin.PngImageFile image mode=L size=120x120 at 0x1FE2A0FC940>]
任何建议都会对我有帮助。谢谢。我认为发生错误是因为您将'L'
分配到图像模式
在我的例子中,它在调色板模式下运行良好:'p'
import numpy as np
from PIL import Image
images=[]
for frame_id in range(frame_num):
# check image mode of target data
im_pil = Image.open("frame_id"+ ".png").convert('P')
images.append(im_pil)
images[0].save('out.gif', save_all=True, append_images=images[1:])
请注意,GIF文件总是作为灰度('L')或调色板模式('p')图像读取
参考
只是一个猜测,但您的图像似乎是灰度(L
)但它似乎在寻找调色板,因此请尝试在打开时切换到调色板模式,即im=Image.open(Image.convert('P')
@MarkSetchell抱歉保持沉默。它真的起作用了!谢谢muchI已经编辑了答案,你拒绝它,并把它作为你自己的坏东西发表
AttributeError: 'NoneType' object has no attribute 'palette'
import numpy as np
from PIL import Image
images=[]
for frame_id in range(frame_num):
# check image mode of target data
im_pil = Image.open("frame_id"+ ".png").convert('P')
images.append(im_pil)
images[0].save('out.gif', save_all=True, append_images=images[1:])