imageio:如何提高输出gif的质量? [英] imageio: How to increase quality of output gifs?

查看:209
本文介绍了imageio:如何提高输出gif的质量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我有一个要串在一起成动画gif的.png(PIL)图像列表
  • 为此,我目前正在使用 imageio
  • 但是,我找不到一种方法来产生高质量的gifs
  • I have a list of .png (PIL) images I want to string together into an animated gif
  • To do this, I am currently using the imageio library
  • However, I cannot find a way to do this to produce good quality gifs

据我所知,我可以更改两种设置.用于读取.png的 imageio.imread()设置,以及用于写入gif的 imageio.mimwrite()设置.根据 imageio.help()

As far as I know, there are two types of settings I can change. The imageio.imread() settings for reading .pngs, and the imageio.mimwrite() settings for writing gifs. According to imageio.help(),

  1. imageio.imread()仅对 PNG-PIL ignoregamma 需要 one 读取参数布尔值.这不会更改我的输出gif的任何内容.
  2. imageio.mimwrite()可以引用两种格式.第一个是 GIF-PIL .此格式的输出仅显示一帧,因此是不可取的.在此处输出.
  3. imageio.mimwrite()具有第二种格式 GIF-FI .通过以下选项,这将产生更多有希望的输出:
    • 'quantizer':'wu'生成具有指定帧和帧频的完整gif,但产生损坏"的质量.在此处输出.
    • 'quantizer':'nq'生成的完整gif具有比"wu"更好的更少损坏"质量,但处理颜色不好.注意右下角的图例如何改变其颜色.在此处输出.
  1. imageio.imread() has one read paramter only for PNG-PIL, ignoregamma which takes a boolean. This does not change anything for my output gifs.
  2. imageio.mimwrite() can refer to two formats. The first is GIF-PIL. The output from this format only shows one frame, and is thus undesirable. Output here.
  3. imageio.mimwrite() has the second format GIF-FI. This produces more promising outputs with the following options:
    • 'quantizer':'wu' generates a full gif with specified frames and frame rates, but produces a 'corrupted' kind-of quality. Output here.
    • 'quantizer':'nq' generates a full gif with better 'less corrupted' quality than 'wu', but does not handle colour well. Notice how the legend in the bottom right tends to change its colour. Output here.


以下是迄今为止我能获得的最佳质量的相关代码( GIF-FI nq )

def gen_gif(self, datetime_list):
    kwargs_write = {'fps':5.0, 'quantizer':'nq'}
    frames = []
    for datetime in datetime_list:
        frames.append(imageio.imread(datetime+'.png'))
    exportname = '{} to {}.gif'.format(datetime_list[0], datetime_list[-1])
    imageio.mimsave(exportname, frames, 'GIF-FI', **kwargs_write)

使用一个字符串列表参数调用该函数,该字符串包含要编译为gif的.png图像的完整路径.

The function is called with one list parameter of strings containing the full path to the .png images to be compiled to the gif.

推荐答案

GIF格式每帧只能处理256种颜色. quantizer 参数确定用于查找这些颜色的方法.

The GIF format can only handle 256 colors per frame. The quantizer parameter determines the method that will be used to find these colors.

控制使用哪种颜色的最佳方法可能是减少自己的颜色数量(减少到256种).

The best way to control which colors will be used is probably to reduce the number of colors (to 256) on your own.

这篇关于imageio:如何提高输出gif的质量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆