Leanpub Header

Skip to main content

Image Processing in Python

Processing raster images with the Pillow library

Minimum price

$14.99

$24.99

You pay

$24.99

Author earns

$19.99
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
157
Pages
34,423Words
About

About

About the Book

Pillow is the most popular Python image processing library. It provides many of the features found in imaging applications like Photoshop or GIMP, such as loading, saving, resizing, transforming images, as well as converting colours and applying filters, enhancements, and effects. This book will teach you how to use simple Python code to automate these functions using the Pillow library, so that your programs can incorporate advanced image processing. It provides a comprehensive guide to Pillow, in plain language and with lots of examples.

Share this book

Categories

Author

About the Author

Martin McBride

Martin McBride is a software developer, specialising in computer graphics, sound, and mathematical programming. He has been writing code since the 1980s in a wide variety of languages from assembler through to C++, Java and Python. He writes for PythonInformer.com and is the author of Functional Programming in Python. He is interested in generative art and works on the generativepy open source project.

Contents

Table of Contents

Preface

  1. Who is this book for?
  2. About the author
  3. Keep in touch

Introduction

  1. Versions
  2. Example sources on github
  3. IBitmap images

1Introduction to bitmap imaging

  1. 1.1What is a bitmap image?
  2. 1.2Spatial sampling
  3. 1.3Colour representation
  4. 1.4File formats
  5. 1.5Vector images

2Computer colour

  1. 2.1Visible light
  2. 2.1.1Frequency and wavelength
  3. 2.2What is colour?
  4. 2.2.1Non-spectral colours
  5. 2.3How we see colour
  6. 2.4The RGB colour model
  7. 2.4.1Displaying colour
  8. 2.4.2Representing RGB colours as a percentage
  9. 2.4.3Floating point representation
  10. 2.4.4Byte value representation
  11. 2.5Colour resolution
  12. 2.6Greyscale colour model
  13. 2.7The CMYK colour model
  14. 2.7.1The K component
  15. 2.8HSL/HSB colour models
  16. 2.9HSL variants
  17. 2.10Perceptual colour models
  18. 2.10.1CIE spaces
  19. 2.11Colour management
  20. 2.11.1Gamuts

3Bitmap image data

  1. 3.1Data layout
  2. 3.28-bit per channel images
  3. 3.2.124-bit RGB
  4. 3.2.232-bit CMYK
  5. 3.2.38-bit greyscale
  6. 3.2.432-bit RGBA
  7. 3.3Bitmap data with fewer levels
  8. 3.3.18-bit RGB
  9. 3.3.216-bit RGB
  10. 3.3.3Dithering
  11. 3.4Bilevel images
  12. 3.5Bitmap data with more levels
  13. 3.6Palette based images
  14. 3.6.1Images with more than 256 colours
  15. 3.7Handling transparency
  16. 3.7.1Alpha channel
  17. 3.7.2Transparent palette entry
  18. 3.7.3Transparent colour
  19. 3.8Interlacing and alternate pixel ordering

4Image file formats

  1. 4.1Why are there so many formats?
  2. 4.2Image data and metadata
  3. 4.3Image compression
  4. 4.3.1Lossless compression
  5. 4.3.2Lossy compression
  6. 4.4Some common file formats
  7. 4.4.1PNG format
  8. 4.4.2JPEG format
  9. 4.4.3GIF format
  10. 4.4.4BMP format
  11. 4.5Animation
  12. IIPillow library

5Introduction to Pillow

  1. 5.1Pillow and PIL
  2. 5.2Installing Pillow
  3. 5.3Main features of Pillow

6Basic imaging

  1. 6.1The Image class
  2. 6.2Creating and displaying an image
  3. 6.3Saving an image
  4. 6.4Handling colours
  5. 6.4.1Converting strings to colours
  6. 6.5Creating images
  7. 6.6Opening an image
  8. 6.7Image processing
  9. 6.8Rotating an image
  10. 6.9Creating a thumbnail
  11. 6.10Image modes

7Image class

  1. 7.1Example code
  2. 7.2Creating images
  3. 7.2.1Image.new
  4. 7.2.2Image.open
  5. 7.2.3copy
  6. 7.2.4Other methods
  7. 7.3Saving images
  8. 7.4Image generators
  9. 7.5Working with image bands
  10. 7.5.1getbands
  11. 7.5.2split
  12. 7.5.3merge
  13. 7.5.4getchannel
  14. 7.5.5putalpha

8ImageOps module

  1. 8.1Image resizing functions
  2. 8.1.1expand
  3. 8.1.2crop
  4. 8.1.3scale
  5. 8.1.4pad
  6. 8.1.5fit
  7. 8.2Image transformation functions
  8. 8.2.1flip
  9. 8.2.2mirror
  10. 8.2.3exif-transpose
  11. 8.3Colour effects
  12. 8.3.1grayscale
  13. 8.3.2colorize
  14. 8.3.3invert
  15. 8.3.4posterize
  16. 8.3.5solarize
  17. 8.4Image adjustment
  18. 8.4.1autocontrast
  19. 8.4.2equalize
  20. 8.5Deforming images
  21. 8.5.1How deform works
  22. 8.5.2getmesh
  23. 8.5.3A wave transform
  24. 8.5.4Other deformations

9Image attributes and statistics

  1. 9.1Attributes
  2. 9.1.1File size
  3. 9.1.2File name
  4. 9.1.3File format
  5. 9.1.4Mode and bands
  6. 9.1.5Palette
  7. 9.1.6Info
  8. 9.1.7Animation
  9. 9.1.8EXIF tags
  10. 9.2Image statistics
  11. 9.2.1Image histogram
  12. 9.2.2Masking
  13. 9.2.3Other Image statistics
  14. 9.2.4ImageStat module

10Enhancing and filtering images

  1. 10.1ImageEnhance
  2. 10.1.1Brightness
  3. 10.1.2Contrast
  4. 10.1.3Color
  5. 10.1.4Sharpness
  6. 10.2ImageFilter
  7. 10.3Predefined filters
  8. 10.4Parameterised filters
  9. 10.4.1Blurring functions
  10. 10.4.2Unsharp masking
  11. 10.4.3Ranking and averaging filters
  12. 10.5Defining your own filters

11Image compositing

  1. 11.1Simple blending
  2. 11.1.1Image transparency
  3. 11.1.2ImageChops blend function
  4. 11.1.3ImageChops composite function
  5. 11.2Blend modes
  6. 11.2.1Addition
  7. 11.2.2Subtraction
  8. 11.2.3Lighter and darker
  9. 11.2.4Multiply and screen
  10. 11.2.5Other blend modes
  11. 11.3Logical combinations

12Drawing on images

  1. 12.1Coordinate system
  2. 12.2Drawing shapes
  3. 12.2.1Drawing rectangles
  4. 12.2.2Drawing other shapes
  5. 12.2.3Points
  6. 12.3Handling text
  7. 12.3.1Drawing simple text
  8. 12.3.2Font and text metrics
  9. 12.3.3Anchoring
  10. 12.3.4Drawing multiline text
  11. 12.4Paths
  12. 12.4.1Drawing a path
  13. 12.4.2Transforming paths
  14. 12.4.3Mapping points

13Accessing pixel data

  1. 13.1Processing an image
  2. 13.2Creating an image
  3. 13.3Performance

14Integrating Pillow with other libraries

  1. 14.1NumPy integration
  2. 14.1.1Converting a Pillow image to Numpy
  3. 14.1.2Image data in a NumPy array
  4. 14.1.3Modifying the NumPy image
  5. 14.1.4Converting a NumPy array to a Pillow image
  6. IIIReference

15Pillow colour representation

  1. 15.1Hexadecimal colour specifiers
  2. 15.2RGB functions
  3. 15.3HSL functions
  4. 15.4HSV functions
  5. 15.5Named colours
  6. 15.6Example
  7. 15.7Image modes

More books from this author

  1. Numpy Recipes
  2. Computer Graphics in Python with Pycairo
  3. Functional Programming in Python

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub