Manipulating Many Images at Once Using Photoshop, GIMP, ImageMagick, PIL and OpenCV: Introduction (Part 1 of 6)
When working with a group of images, sometimes we want to manipulate each image within the group in the the same way. For example, resizing to thumbnails or applying a filter to smooth out noise. However, working on one image at a time is quite tedious & time consuming and prone to error. How can this be made simpler?
Over the next several posts, we will explore how we can apply simple or complex modifications to any number of images at the same time. This is referred to as batch processing.
How to Process Images in Batch
Batch processing of images is the automatic application of identical changes to all images at the same time (or in the same run). For example, say I had 10 photos of my adventures at the zoo, but they are too large to share with my animal loving friends & family as e-mail attachments. While I could open, resize, save & close each image individually, my eyes would glaze over after the first few. I would much rather create a set of commands that will be applied to each image automatically.
This requires a graphics editing program that supports processing images in batch, or writing a script using image processing libraries. We will be looking at batch processing with Adobe Photoshop, GIMP, ImageMagick, PIL (Python Imaging Library) and OpenCV. The first two are editing programs and the latter are libraries. All require coding to manipulate images in batch. However, Photoshop offers an all gui approach which relies on recording of a set of user actions that then can be “played” (or executed) on any image.
Image Manipulations: Resizing & Applying the Sepia Effect
We will implement the following manipulations on our images:
- resize each image into three (3) different sizes: 75%, 50%, 25%, of the original
- apply a sepia tone effect, which is a reddish brown hue that gives the photo an aged look
Resizing or scaling an image is supported in all image editors and libraries. Photoshop and ImageMagick already have sepia functionality available, but we will be applying our own algorithm through image desaturation and blending.
Sepia Tone Effect Algorithm
The sepia tone effect lends an old, antique-ish look to a photo. The following steps will be implemented to achieve a sepia tone effect.
- Desaturate the image. The resulting image is greyscale.
- Apply a mild gaussian blur since most old photos are slightly blurry.
- Add a reddish brown (or dark orange) solid color layer above the photo layer, using the soft light blend mode.
The soft light blend mode provides an effect similar to shining a diffused spotlight on the image. When blending is not supported natively, we will implement it ourselves. Luckily, the math is pretty straightforward. For this we will use the W3C equations for the soft light blending mode.
Coming Up …
Our next post will explore batch processing in Adobe Photoshop.