.. include:: =========================================== Python and the Image Manipulation Library =========================================== :Author: Jeff Rush :Copyright: 2007 Tau Productions Inc. :License: GNU Free Documentation License :Date: August 10, 2007 :Version: 1 :Series: 5-Minutes with Python An introduction to a widely used 2-d image manipulation package for Python named 'PIL', providing for the viewing, copying, printing filtering and transformation of images, including palette manipulation, pixel filtering and multipage animations. .. footer:: 5-Minutes with Python: Series .. |CLICK| unicode:: U+02794 .. thick rightwards arrow .. container:: handout Hello, my name is Jeff Rush and this talk is part of the "5-Minutes with Python" series. In this brief slideshow I'll provide a survey of the capabilities of the Imaging Library for Python. Although not part of the Python standard library, it is a commonly used component and illustrates the richness of modules available for Python. Roadmap to Talk =============== .. container:: slide-display + `What is PIL and why should I use it?` + `Loading, viewing, saving, printing and grabbing images` + `Transformations of shape, content and color` + `Drawing into and filtering images` + `Operating on multiple images` + `Get PIL and find the community` .. contents:: Table of Contents :class: handout .. container:: handout |CLICK| In this talk I'll highlight the major features of the Imaging Library and why those may be useful to you. |CLICK| I'll cover the movement of images into and out of your programs along several avenues, and |CLICK| facilities for transforming images by shape, pixel content or colorspace, and |CLICK| speak a bit about drawing onto images and filtering images using certain mathematical processes. |CLICK| The Imaging Library can also be used to operate on complex images, such as multipage documents, page-flip animations or compositing one image onto another. |CLICK| I'll conclude with where to get the Imaging Library and where the Python imaging community hangs out. What is PIL? ============ .. container:: slide-display + `Python Imaging Library` + `2-D rasters, not 3-D, not vector` + `reads many formats, writes few` + `more than RGB (CMYK, YCbCr)` + `supports alpha channel` + `cross-platform` .. container:: handout First let's get the name straight. |CLICK| *PIL* is the nickname for the Python Imaging Library but is referenced in your programs as the module *Image*. |CLICK| PIL provides for the manipulation of 2-dimensional raster or pixel-based images, not 3-dimensional nor vector graphics, although we'll see with its postscript support some aspects of vector graphics. |CLICK| PIL identifies and reads many different image formats and intentionally writes only the more common interchange and presentation formats. |CLICK| And it understands images constructed out of more than your traditional RGB components, such as CMYK four-color model and YCbCr luma/chroma components. |CLICK| PIL allows for the use of an alpha channel, giving you variable control over transparency. |CLICK| And it runs under multiple operating systems, giving you a platform-independent image manipulation capability. Why use it? =========== .. container:: slide-display + `efficient internal representation` + `usable with GUI toolkits` + `useful for archiving` + `image i/o` + `basic ops` + `multipage images` .. container:: handout |CLICK| PIL provides an efficient internal representation of multiple image formats, providing fast operation without having to resort to a compiled programming language, |CLICK| It has hooks to interoperate with several different GUI frameworks, including wxWindows and Tkinter. |CLICK| PIL has features that make it especially suitable to the archiving of images, such as |CLICK| I/O to not just files but also containers such as tarfiles, |CLICK| basic image operations suitable for batch processing, and |CLICK| support for multipage images such as scanned documents. I/O: Loading, Saving, Viewing Images ==================================== .. container:: slide-display + `loading` + `individual files` `with auto-id` + `members of archive containers` + `saving` + `automatic format conversion` + `viewing` + `save and invoke program` + `GUI frameworks: Tkinter, wxWindows` .. container:: handout PIL provides several ways of getting images into and out of your program. |CLICK| Besides |CLICK| reading from files (|CLICK| with automatic format identification), it supports |CLICK| reading from archive containers such as tar files. |CLICK| And when saving out an image, PIL will |CLICK| automatically convert it to the destination format. |CLICK| For quickly viewing an image during development, PIL can |CLICK| save it to disk and run a viewer program. |CLICK| And you can embed your images in various other GUI frameworks. I/O: Printing, Grabbing ======================= .. container:: slide-display + `printing` + `postscript` + `PDF` + `screen capture` + `from clipboard` + `from scanner via SANE` .. container:: handout |CLICK| PIL provides for the writing of images and other drawing elements into |CLICK| postscript and |CLICK| PDF files for printing. Besides file I/O |CLICK| PIL can acquire images from the |CLICK| desktop clipboard and |CLICK| from a scanner device compatible with the SANE scanner interface standard. Geometric Manipulation ====================== .. container:: slide-display + `resizing, thumbnails` + `flipping,` `rotating,` `transforming` + `cropping,` `cutting, pasting` .. container:: handout PIL supports a complete set of geometric manipulations of images, such as |CLICK| resizing, perhaps to provide thumbnail images, and |CLICK| flipping them left-right, top-to-bottom, |CLICK| rotating by any number of degrees, and |CLICK| transforming them with various algorithms. PIL makes it easy to |CLICK| crop images and |CLICK| cut, copy and paste pieces among images, while autoconverting the format of the pieces as needed. Pixel/Colorspace Operations =========================== .. container:: slide-display + `point operations` + `convolutions (blur, emboss, smooth, etc.)` + `color space conversions` + `stats re histograms` .. container:: handout Sometimes you need to apply operations to each pixel or group of pixels. |CLICK| PIL provides for point operations -- where each pixel is run through a value map, either a table or function. For group operations, |CLICK| PIL comes with convolution kernels for blurring, sharpening, embossing and so forth. |CLICK| With PIL you have control over the color space, able to manipulate the palette, increase or decrease the number of colors or replace it entirely. |CLICK| And PIL gives you methods to extract, from all or part of your image, statistics such as mean, sum, count, standard deviation. Returned as a histogram, these methods are useful for automatic contrast enhancement and global statistical analysis. Drawing into Images =================== .. container:: slide-display + `what can be drawn?` + `images` + `text of various fonts (bitmap or truetype)` + `graphical elements (points, lines, etc.)` + `where can it be drawn?` + `onto bitmaps` + `onto postscript` .. container:: handout PIL lets you draw onto images, whether annotating or retouching existing images, or generating graphics on the fly for web use. The first aspect to consider is |CLICK| **what can be drawn onto an image**. Certainly |CLICK| images can be placed onto other images but |CLICK| also text, with control over the font used, as well as |CLICK| geometric elements such as points, lines, boxes and curves. And the second aspect is |CLICK| **where can we draw these?** |CLICK| Onto other bitmaps of course, but also |CLICK| onto postscript pages, in which case they are vector or path-based, and resolution independent. Image Sequencing ================ .. container:: slide-display + `frame iteration` + `FLI/FLC, GIF animations` + `multipage TIFF` .. container:: handout Although not a comprehensive animation tool, |CLICK| PIL implements *seek* and *tell* methods on |CLICK| those image formats |CLICK| that support multiple images. With PIL you can take a sequence of images apart, operate on them and put them back together again. For Further Reading =================== .. container:: slide-display + `Main PIL website:` `http://www.pythonware.com/products/pil/` + `Python Image SIG mailing list` `http://mail.python.org/mailman/listinfo/image-sig` + `Contact me:` `Jeff Rush (Python Advocacy Coordinator)` `` .. container:: handout |CLICK| |CLICK| PIL is an open source product of Secret Labs AB, under the banner of PythonWare. Besides being free, they also offer commercial support contracts. |CLICK| |CLICK| Within the Python community, those interested in imaging hang out on the mailing list of the Image special interest group |CLICK| |CLICK| |CLICK| And if you have any comments or suggestions about this talk, you can email me at "advocate" at "python dot org". We are looking for speakers to record other talks, 5-minutes or longer. These slides and script are available under the Creative Commons Attribute-ShareAlike license, for use in your own presentations. .. Local Variables: mode: rst mode: outline-minor End: