Wednesday, March 14, 2018

Batch Enhance and Resize images using GIMP

GIMP is a free and open source replacement for Photoshop. A great tutorial for enhancing photos with GIMP is described in this link. It makes photos much brighter and vibrant.

steps involved are:

1. duplicate image layer twice
2. Desaturate (Colors -> Desaturate) topmost layer selecting luminosity option.
3. Invert the color of the layer from Colors -> Invert
4. Do Gaussian Blur (Filters ->Blur ->Gaussian Blur), with setting radii as 20 and blur method as RLE.
5. From the Layers panel set the opacity of top layer as 40.
6. Merge down the top layer to the middle layer
7. Change the blend mode of the middle layer (top layer now, after the merge) as 'Grain Merge'.
8. You can test the changes by toggling the visibility of the top layer.
9. Finally merge down the top layer.

That's a lot of steps, to remember. That's where scripting comes to use. (Photoshop has batch mode). GIMP provides 2 scripting languages 'Script-Fu' and 'Python-Fu'. Scripting is also useful to process a folder of photos in a single click, in batch mode.

Script-Fu is evolved from Scheme language, and is bit different in syntax from usual programming and scripting languages. Each statement is enclosed in parentheses, each statement begins with a function or an operator, functions are defined with 'define', variables assigned with 'set!' and variables declared with 'let*'. Edit the script using a text editor and store in '.gimp-2.8/scripts' folder in home folder (in Linux) as *.scm file. First I'll describe a script to resize individual photos and in batch mode from a folder.

In this I've defined two procedures my-resize and batch-resize and registered them using script-fu-register and script-fu-menu-register functions. To be able to use the batch procedure without opening an image, while registering , pass the 6th parameter as "" instead of any image format or as any format with "*" as we did with my-resize function. To work with currently opened image, pass an image parameter and drawable parameter as first 2 parameters with 0 as default value. 'car' and 'cdr' functions are used to access the list members.

Save this script in the script folder and in Gimp select Filters->Script-Fu->Refresh Scripts. the script will appear in Filter->Mine menu.

Next, I'll write another script to enhance the image using the method I described above. I'll write a script to batch automate, which will first resize the image, and then enhance it, because enhancing will work faster in a smaller size image file.