Introduction to wrapper class in the ImageSequence module of Python image processing library PIL

Source: Internet
Author: User
Tags image processing library

Introduction to wrapper class in the ImageSequence module of Python image processing library PIL

The ImageSequence module contains a wrapper class that allows users to iteratively access each frame of the image sequence.

I. Functions of the ImageSequence Module

1. Iterator

Definition: ImageSequence. Iterator (image )? Iterator instance

Meaning: Create an iterator instance to allow users to access all frames in the sequence cyclically.

Example: See the following example.

Ii. ImageSequence Module Method

1. Operator

Definition: Operator []

Meaning: the user calls this operator and starts to access it from 0. When no other frame image exists, this iterator will generate an IndexError exception.

Example:

from PIL import Image, ImageSequenceim = Image.open("D:\\Code\\Python\\test\\img\\test01.gif")index = 1for 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 + 1iter = ImageSequence.Iterator(im)print "image 10: mode %s, size %s" % (iter[10].mode, iter[10].size)iter[10].show()

The image test01.gif contains multiple dynamic images. The ImageSequence. Iterator (im) function obtains the Iterator of the image object im, extracts each image one by one, and prints their modes and sizes. The corresponding image in the iterator is obtained through the operator. Iter [10] corresponds to the tenth image.

The program output is as follows:

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)

Figure test01.gif:

The second image is:

Of the 20th images:

 

The tenth image obtained using the operator [] is as follows:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.