Image Processing in Python
Image Processing in Python
Processing raster images with the Pillow library
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.
Table of Contents
-
-
Preface
- Who is this book for?
- About the author
- Keep in touch
-
Introduction
- Versions
- Example sources on github
-
Preface
-
I Bitmap images
-
1 Introduction to bitmap imaging
- 1.1 What is a bitmap image?
- 1.2 Spatial sampling
- 1.3 Colour representation
- 1.4 File formats
- 1.5 Vector images
-
2 Computer colour
-
2.1 Visible light
- 2.1.1 Frequency and wavelength
-
2.2 What is colour?
- 2.2.1 Non-spectral colours
- 2.3 How we see colour
-
2.4 The RGB colour model
- 2.4.1 Displaying colour
- 2.4.2 Representing RGB colours as a percentage
- 2.4.3 Floating point representation
- 2.4.4 Byte value representation
- 2.5 Colour resolution
- 2.6 Greyscale colour model
-
2.7 The CMYK colour model
- 2.7.1 The K component
- 2.8 HSL/HSB colour models
- 2.9 HSL variants
-
2.10 Perceptual colour models
- 2.10.1 CIE spaces
-
2.11 Colour management
- 2.11.1 Gamuts
-
2.1 Visible light
-
3 Bitmap image data
- 3.1 Data layout
-
3.2 8-bit per channel images
- 3.2.1 24-bit RGB
- 3.2.2 32-bit CMYK
- 3.2.3 8-bit greyscale
- 3.2.4 32-bit RGBA
-
3.3 Bitmap data with fewer levels
- 3.3.1 8-bit RGB
- 3.3.2 16-bit RGB
- 3.3.3 Dithering
- 3.4 Bilevel images
- 3.5 Bitmap data with more levels
-
3.6 Palette based images
- 3.6.1 Images with more than 256 colours
-
3.7 Handling transparency
- 3.7.1 Alpha channel
- 3.7.2 Transparent palette entry
- 3.7.3 Transparent colour
- 3.8 Interlacing and alternate pixel ordering
-
4 Image file formats
- 4.1 Why are there so many formats?
- 4.2 Image data and metadata
-
4.3 Image compression
- 4.3.1 Lossless compression
- 4.3.2 Lossy compression
-
4.4 Some common file formats
- 4.4.1 PNG format
- 4.4.2 JPEG format
- 4.4.3 GIF format
- 4.4.4 BMP format
- 4.5 Animation
-
1 Introduction to bitmap imaging
-
II Pillow library
-
5 Introduction to Pillow
- 5.1 Pillow and PIL
- 5.2 Installing Pillow
- 5.3 Main features of Pillow
-
6 Basic imaging
- 6.1 The Image class
- 6.2 Creating and displaying an image
- 6.3 Saving an image
-
6.4 Handling colours
- 6.4.1 Converting strings to colours
- 6.5 Creating images
- 6.6 Opening an image
- 6.7 Image processing
- 6.8 Rotating an image
- 6.9 Creating a thumbnail
- 6.10 Image modes
-
7 Image class
- 7.1 Example code
-
7.2 Creating images
- 7.2.1 Image.new
- 7.2.2 Image.open
- 7.2.3 copy
- 7.2.4 Other methods
- 7.3 Saving images
- 7.4 Image generators
-
7.5 Working with image bands
- 7.5.1 getbands
- 7.5.2 split
- 7.5.3 merge
- 7.5.4 getchannel
- 7.5.5 putalpha
-
8 ImageOps module
-
8.1 Image resizing functions
- 8.1.1 expand
- 8.1.2 crop
- 8.1.3 scale
- 8.1.4 pad
- 8.1.5 fit
-
8.2 Image transformation functions
- 8.2.1 flip
- 8.2.2 mirror
- 8.2.3 exif-transpose
-
8.3 Colour effects
- 8.3.1 grayscale
- 8.3.2 colorize
- 8.3.3 invert
- 8.3.4 posterize
- 8.3.5 solarize
-
8.4 Image adjustment
- 8.4.1 autocontrast
- 8.4.2 equalize
-
8.5 Deforming images
- 8.5.1 How deform works
- 8.5.2 getmesh
- 8.5.3 A wave transform
- 8.5.4 Other deformations
-
8.1 Image resizing functions
-
9 Image attributes and statistics
-
9.1 Attributes
- 9.1.1 File size
- 9.1.2 File name
- 9.1.3 File format
- 9.1.4 Mode and bands
- 9.1.5 Palette
- 9.1.6 Info
- 9.1.7 Animation
- 9.1.8 EXIF tags
-
9.2 Image statistics
- 9.2.1 Image histogram
- 9.2.2 Masking
- 9.2.3 Other Image statistics
- 9.2.4 ImageStat module
-
9.1 Attributes
-
10 Enhancing and filtering images
-
10.1 ImageEnhance
- 10.1.1 Brightness
- 10.1.2 Contrast
- 10.1.3 Color
- 10.1.4 Sharpness
- 10.2 ImageFilter
- 10.3 Predefined filters
-
10.4 Parameterised filters
- 10.4.1 Blurring functions
- 10.4.2 Unsharp masking
- 10.4.3 Ranking and averaging filters
- 10.5 Defining your own filters
-
10.1 ImageEnhance
-
11 Image compositing
-
11.1 Simple blending
- 11.1.1 Image transparency
- 11.1.2 ImageChops blend function
- 11.1.3 ImageChops composite function
-
11.2 Blend modes
- 11.2.1 Addition
- 11.2.2 Subtraction
- 11.2.3 Lighter and darker
- 11.2.4 Multiply and screen
- 11.2.5 Other blend modes
- 11.3 Logical combinations
-
11.1 Simple blending
-
12 Drawing on images
- 12.1 Coordinate system
-
12.2 Drawing shapes
- 12.2.1 Drawing rectangles
- 12.2.2 Drawing other shapes
- 12.2.3 Points
-
12.3 Handling text
- 12.3.1 Drawing simple text
- 12.3.2 Font and text metrics
- 12.3.3 Anchoring
- 12.3.4 Drawing multiline text
-
12.4 Paths
- 12.4.1 Drawing a path
- 12.4.2 Transforming paths
- 12.4.3 Mapping points
-
13 Accessing pixel data
- 13.1 Processing an image
- 13.2 Creating an image
- 13.3 Performance
-
14 Integrating Pillow with other libraries
-
14.1 NumPy integration
- 14.1.1 Converting a Pillow image to Numpy
- 14.1.2 Image data in a NumPy array
- 14.1.3 Modifying the NumPy image
- 14.1.4 Converting a NumPy array to a Pillow image
-
14.1 NumPy integration
-
5 Introduction to Pillow
-
III Reference
-
15 Pillow colour representation
- 15.1 Hexadecimal colour specifiers
- 15.2 RGB functions
- 15.3 HSL functions
- 15.4 HSV functions
- 15.5 Named colours
- 15.6 Example
- 15.7 Image modes
-
More books from this author
- Numpy Recipes
- Computer Graphics in Python with Pycairo
- Functional Programming in Python
-
15 Pillow colour representation
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.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned$12,046,757writing, 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
Top Books
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Talking with Tech Leads
Patrick KuaA book for Tech Leads, from Tech Leads. Discover how more than 35 Tech Leads find the delicate balance between the technical and non-technical worlds. Discover the challenges a Tech Lead faces and how to overcome them. You may be surprised by the lessons they have to share.The Rails 7 Way
Obie Fernandez, Lucas Dohmen, and Tom Henrik AadlandThe Rails™ 7 Way is the comprehensive, authoritative reference guide for professionals delivering production-quality code using modern Ruby on Rails. It illuminates the entire Rails 7 API, its most powerful idioms, design approaches, and libraries. Building on the previous editions, this edition has been heavily refactored and updated.
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
JavaScript for hackers
Gareth HeyesLearn how to find interesting behaviour and flaws in JavaScript. Reading this book you will find the latest and greatest techniques for hacking JavaScript and generating XSS payloads. Includes ways to construct JavaScript using only +[]()! characters. Never heard of DOM Clobbering? This book has all the details.
Functional Event-Driven Architecture
Gabriel VolpeExplore the event-driven architecture (EDA) in a purely functional way. Learn to design and develop distributed systems that scale. Identify common design patterns in such systems.
Take your functional programming skills to the next level by joining me in developing a distributed system powered by Apache Pulsar and Fs2 streams, all in Scala 3!
Build Your Own Redis with C/C++
build-your-own.org- Why build Redis? Two topics to learn: network programming and data structures.
- Why from scratch? A quote from Richard Feynman: "What I cannot create, I do not understand".
- Why C? C is widely used for system programming and infrastructure software.
- Why a book? The real Redis is complex, this book breaks down the essense into easy-to-digest steps.
Machine Learning Q and AI
Sebastian Raschka, PhDHave you recently completed a machine learning or deep learning course and wondered what to learn next? With 30 questions and answers on key concepts in machine learning and AI, this book provides bite-sized bits of knowledge for your journey to becoming a machine learning expert.
Implementing DDD, CQRS and Event Sourcing
Alex LawrenceLearn how to implement DDD, CQRS and Event Sourcing. Understand the theory and put it into practice with JavaScript and Node.js. Utilize an extensive source code bundle and an interactive execution feature for a hands-on experience.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Top Bundles
- #1
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
Modern C++ Collection
3 Books
Get All about Modern C++C++ Standard Library, including C++20Concurrency with Modern C++, including C++20C++20Each book has about 200 complete code examples. Updates are included. When I update one of the books, you immediately get the updated bundle. You can expect significant updates to each new C++ standard (C++23, C++26, .. ) and also... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #5
1500 QUIZ COMMENTATI (3 libri)
3 Books
Tre libri dei QUIZ MMG Commentati al prezzo di DUE! I QUIZ dei concorsi ufficiali di Medicina Generale relativi agli anni: 2000-2001-2003-2012-2013-2014-2015-2016-2017-2018-2019-2020-2021 +100 inediti Raccolti in unico bundle per aiutarvi nello studio e nella preparazione al concorso. All'interno di ogni libro i quiz sono stati suddivisi per... - #6
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #9
Growing Agile: The Complete Coach's Guide
7 Books
Growing Agile: Coach's Guide Series This bundle provides a collection of training and workshop plans for a variety of agile topics. The series is aimed at agile coaches, trainers and ScrumMasters who often find themselves needing to help teams understand agile concepts. Each book in the series provides the plans, slides, handouts and activity... - #10
Mastering Containers
2 Books
Docker and Kubernetes are taking the world by storm! These books will get you up-to-speed fast! Docker Deep Dive is over 400 pages long, and covers all objectives on the Docker Certified Associate exam.The Kubernetes Book includes everything you need to get up and running with Kubernetes!