Gimp: Red Eye Effect removal using gimp script
Posted by Jai on October 22, 2012
Gimp is a well know Image Manipulation Program. The program provides plenty of nice features for image manipulation. On top of that the plugin architecture of the tool provides end users to write own custom scripts to do specific operations. In this post we will cover how we can use gimp features for the Red Eye Effect Removal. What gimp offers out of the box and how we can extend the same functionality to our needs.
To know more about Red Eye Effect and red eye removal tools and techniques, please have a look at earlier posts,
- Image Manipulation: Red Eye Effect removal tools, techniques & solutions
- Image Manipulation: Using ImageMagick from Java
We will cover the following topics in here,
- What is gimp and what features it provides
- What do you mean by batch mode with gimp
- What are different plugins offered by gimp
- Gimp in built red eye removal plugin
- Extending gimp red eye removal plugin
GIMP is the GNU Image Manipulation Program. It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Have a look at feature list, Features.
GIMP Batch Mode
GIMP comes with a so-called batch mode that allows you to do image processing from the command line.
To start gimp in batch mode
gimp -b -
In order to do image processing from the command-line, you usually use the Script-Fu batch interpreter. This is the default, which makes things simple. To give you an impression of what can be done, try the interactive console mode
To exit the batch mode, you need to quit the console
-b '(gimp-quit 0)'
Script-Fu allows you to do scripting inside gimp.
Script-Fu is what the Windows world would call “macros” But Script-Fu is more powerful than that. Script-Fu is based on an interpreting language called Scheme, and works by using querying functions to the GIMP database.
Have a look at scripting Tutorial.
Gimp plugin repository is the place for extensions of gimp program.
Check the complete list to see already available extensions for the program.
GIMP Red Eye Removal Plugin
The Red Eye Removal plug-in has been included in the default GIMP package (see Filters -> Enhance -> Red Eye Removal).
Using red-eye-removal plugin inside the gimp program
Check the step by step tutorial to see how you can use this plugin from gimp program for the red eye removal.
Red Eye Original image:
Red Eye Removal applied:
Using red-eye-removal plugin from Script-Fu console
Using red-eye-removal plugin from batch mode
The plugin is designed to work from inside the gimp program. We would have to do additional scripting to be able to use the plugin from batch model. See below example for how to do it.
GIMP Red Eye Removal Custom Script
RedEyeRemovalGimpPlugin.scm custom script to call gimp red eye removal plugin.
; RedEyeRemovalGimpPlugin.scm - GIMP Script-Fu to remove red eye ; This Script-Fu must be put in The GIMP's script directory ; (e.g., $HOME/.gimp-1.2/scripts). ; For command-line invocation, use the shell script GimpBatchModeScript.sh ; For interactive invocation, run The GIMP and go to ; Xtns -> Script-Fu -> Jai ; ;Check if the plugin is installed ;(if (defined? 'RedEyeRemovalGimpPlugin) (gimp-message "It Exists") (gimp-message "Doesnt Exist")) (define (RedEyeRemovalGimpPlugin infile outfile threshold) ; Read input file and set as image ; mark the image as active drawable (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE infile infile))) (drawable (car (gimp-image-active-drawable image))) ) ; Remove the red eye ; Set the threshold value for red eye removal to use entered value (plug-in-red-eye-removal RUN-NONINTERACTIVE image drawable threshold ) ; Save active drawable as output file. (gimp-file-save RUN-NONINTERACTIVE image drawable outfile outfile ) ; ) ) (script-fu-register ; I always forget these ... "RedEyeRemovalGimpPlugin" ; script name to register "/Xtns/Script-Fu/Jai/RedEyeRemovalGimpPlugin" ; where it goes "RedEyeRemovalGimpPlugin" ; script description "Jai" ; author "Jai; GNU GPL" ; copyright "2012-02-21" ; date "" ; type of image SF-FILENAME "Infile" "infile.jpg" ; default parameters SF-FILENAME "Outfile" "outfile.jpg" SF-VALUE "Threshold" "30" )
You are using gimp existing red eye removal functionality and exposing the plugin with additional capability to remove red eye effect from input file and storing the file as another output file. Rather than editing the same file you can save the modified file as different file. Your can also control the saturation of the color, threshold for the intensity of the color.
The complete scheme file can file downloaded from, RedEyeRemovalGimpPlugin.scm
Executing GIMP Red Eye Removal Custom Script from batch mode
To execute the above custom script, lets say you have copied the script to $HOME/.gimp-1.2/scripts gimp path and it is available for gimp console.
./gimp-console-2.6.sh --verbose --new-instance --console-messages --no-interface --no-data --no-fonts -b '(RedEyeRemovalGimpPlugin "/tmp/test-red-eye.jpg" "/tmp/test-red-eye-removed.jpg" 30)' -b '(gimp-quit 0)'
Few points to remember regarding the above scripts,
- “-b” to run the gimp in batch mode
- “–verbose” for debug purpose to see what gimp is doing
- “–new-instance” will always start the operation in new gimp instance
- “-no-interface/data/fonts” parameters are used as the plugin is not using additional functionality of data and fonts etc.
- “gimp-quit” to make sure to quit the gimp console once operation is finished.
- The single and double quotes, you need to check if you using unix or windows environment.
Red Eye Original:
Red Eye Removal applied using above batch script with threshold value of 30.
You should now be able to remove red eye effect using gimp in built plugin for the same and you can run it as command line utility. By controlling input, output files and threshold you can control the color saturation of red eye reduction and can also provide option to end user to control the same.