zoukankan      html  css  js  c++  java
  • Python图像处理库PIL的ImageSequence模块介绍

    ImageSequence模块包括了一个wrapper类,它能够让用户迭代訪问图形序列中每一帧图像。

    一、ImageSequence模块的函数

    1、  Iterator

    定义:ImageSequence.Iterator(image) Iterator instance

    含义:创建一个迭代器实例,让用户循环訪问序列中的全部帧图像。

    样例:见以下的样例。

    二、ImageSequence模块的方法

    1、  Operator

    定义:Operator []

    含义:用户调用这个操作器,从0開始訪问。

    当没有其它帧图像时。这个迭代器将产生一个IndexError异常。

    样例:

    from PIL import Image, ImageSequence
    
    im = Image.open("D:\Code\Python\test\img\test01.gif")
    
    index = 1
    for frame in ImageSequence.Iterator(im):
        print "image: index %d, mode %s, size %s" % (index, frame.mode, frame.size)
        frame.save("frame%d.png" % index)
        index = index + 1
    
    iter = ImageSequence.Iterator(im)
    print "image 10: mode %s, size %s" % (iter[10].mode, iter[10].size)
    iter[10].show()

    图像test01.gif为多张动态图像。

    通过函数ImageSequence.Iterator(im)获取了图像对象im的迭代器,然后从当中逐张取出每张图片。打印了它们的模式和尺寸。后面通过操作符[]获取迭代器中的相应图像。iter[10]相应着第十张图像。

    该程序输出例如以下:

    image:index 1, mode P, size (450, 450)

    image:index 2, mode P, size (450, 450)

    image:index 3, mode P, size (450, 450)

    image:index 4, mode P, size (450, 450)

    image:index 5, mode P, size (450, 450)

    image:index 6, mode P, size (450, 450)

    image:index 7, mode P, size (450, 450)

    image:index 8, mode P, size (450, 450)

    image:index 9, mode P, size (450, 450)

    image:index 10, mode P, size (450, 450)

    image:index 11, mode P, size (450, 450)

    image:index 12, mode P, size (450, 450)

    image:index 13, mode P, size (450, 450)

    image:index 14, mode P, size (450, 450)

    image:index 15, mode P, size (450, 450)

    image:index 16, mode P, size (450, 450)

    image:index 17, mode P, size (450, 450)

    image:index 18, mode P, size (450, 450)

    image:index 19, mode P, size (450, 450)

    image:index 20, mode P, size (450, 450)

    image:index 21, mode P, size (450, 450)

    image:index 22, mode P, size (450, 450)

    image:index 23, mode P, size (450, 450)

    image10: mode P, size (450, 450)

    图像test01.gif例如以下:

                                 

    当中第二张图像为:

     

    当中第二十张图像为:

     

     

    后面通过操作符[]获取的第十张图像例如以下:

     

  • 相关阅读:
    从太空到地球某个位置的轨迹录像制作 | Earth Zoom in/out Tutorial (Record Video)
    DNA replication timing数据库
    探索ENCODE数据库 | Encyclopedia of DNA Elements
    第100天: 三木板模型算法项目实战
    第99天:UDP 编程
    第98天:图像库 PIL 实例—验证码去噪
    第97天:图像库 PIL(二)
    第96天:图像库 PIL(一)
    第95天:StringIO & BytesIO
    第94天:数据分析之 pandas 初步
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7345304.html
Copyright © 2011-2022 走看看