- Create a new image
- Open, Show & Save images (PIL)
- Paste, Merge, Blend images (PIL)
- How to Draw shapes images (PIL)
- How to Crop an image (PIL)
- How to Add Text to images (PIL)
- How to Add Frames to images (PIL)
- How to Resize an image (PIL)
- Brightness, Contrast, Saturation
- Convert image to Grayscale | B&W
- Create Photo Collages
- Digital Image Color Modes
- Digital Image Basics
- Image Manipulation w/ PIL
- Batch Resize Multiple Images (PIL)
- Watermarking Images
- Difference Between 2 Images (PIL)
Image Processing: PIL (pillow) Tutorial
- Image Processing
- What is PIL?
- PIL vs Pillow
- PIL Tutorials
- Python Library Packaging
What is Image Processing?
Image processing is the computational transformation of images. This usually involves working with computer languages to work on image as a 2 dimensional signal through its pixel composition. Image processing also is a branch of signal processing.
Image editing can be the same outcomes of changing, altering, editing, enhancing the image but it usually implies doing those things through gui of image editing software and not as a vector or signal.
Image Processing vs Image Manipulation
Image manipulation, image processing and image editing can all be used interchangeably depending on the context however, one scenario image manipulation differs from image editing is that image manipulation can refer to more substantial changes such as moving objects, removing people, adding object, changing scene etc while image editing can be more appropriate for image enhancing, resizing, rotating type operations.
What is PIL (pillow)?
PIL is an imaging library for Python programming language.
Script is a piece of code that’s used to automate system oriented tasks. When you write code that carries out a practical task without needing compiling this can be called scripting.
PIL has very powerful image processing capabilities and it can handle many types of images (BMP, DIB, EPS, GIF, ICO, IM, JPEG, JPG, JPEG 2000, MSP, PCX, PNG, PPM, SGI, TGA, TIFF, WebP, XBM just to name a few formats) and image modes such as RGB, RGBA, B&W and monochrome.
PIL also works on practically all operating systems including, Windows, Linux, and MacOSX.
PIL v.s. pillow
Pillow is a fork of PIL, Python Imaging Library. PIL was released in late 2009 and maintained until 2011. In 2011 PIL development stopped. Luckily PIL fell on a soft place since pillow library picked up from where it’s left and it continues to exist as pillow today.
This can create some terminology confusion but it’s safe to say that pillow and PIL refer to the same thing in most situations today as the terms became somewhat synonymous.
Python PIL (pillow) Tutorials
Here are some basic and advanced tutorials we have created regarding PIL image processing library in Python.
- How to open, show and save images with PIL
- Digital Image Basics With PIL Library In Python
- How to Resize an Image and Get Size in Python (PIL)
- How to adjust brightness, contrast, sharpness and saturation of images (PIL)
- How to convert an image to B&W or Grayscale
- Digital Image Color Modes
How to Install PIL (pillow)
pip install Pillow or pip3 install Pillow
Commonly used PIL (pillow) Modules
- Image: Most fundamental image operations can be done with it such as:
- opening an image, showing an image, saving an image,
- managing alpha transparency channels,
- converting between image modes,
- merging, blending and combining images,
- copying and pasting images,
- creating new images or image layers,
- reading from and writing to image pixels
- Cropping, rotating, resizing, flipping images
- Transposing images
- ImageEnhance: Can be used for image enhancement operations regarding; color, contrast, brightness and sharpness via these classes:
- ImageDraw: Useful to draw pretty much anything on an image.
- ImageFont: Used to create a font wrapper which can be used to draw text on images (supports bitmap and truetype fonts)
- ImageGrab: Useful to get contents of screen or from the clipboard. Similar function to the printscreen key on keyboard.
- ImageFilter: Includes common useful filters that can be applied to images via many different means such as pixel thresholds, based on minimum pixels, maximum pixels, median pixels etc. Furthermore, these filter objects can be applied via a number of methods such as gaussianblur, boxblur, unsharpmax etc.
- ImageCms: Image color profile management.
- ImageStat: Getting global statistics of images at pixel level such as; mean, minimum, maximum, count, sum, variance, standard deviation of pixels at each band.
- ImageColor: Color table conversion operations
PIL has even more modules but most people will probably use top 6 modules listed here in most cases.
We have learned some digital image basics in this Python tutorial. Before understanding the fundamentals of digital images it’s harder to carry out image processing operations with coding. We have also clarified some of the digital imaging terms such as image processing and image manipulation.
Once you understand each pixel consists of numerical data it becomes a breeze to write Python code to do all kinds of imaging operations.
Then, we have explained how to edit images in Python using PIL (pillow) library through PIL tutorials with Python.
We have also seen other image editing tutorials such as how to resize images as a batch, how to tell different pixels between images etc.