Processing several photos at once

Some of the filters in G’MIC are quite slow, so processing a series of photos one by one can be time-consuming. Luckily it is easy to process them in batch using a terminal window, as shown below on a Linux system. This should work as well on OS X and Windows.

In order to batch process photos with G’MIC you must first install the package gmic. This is not the same software as the GIMP plugin that is called gimp-gmic. You can install gmic via your software manager or download a more recent version from here.

This version of G’MIC contains the default commands. To get all the available commands, use the built-in update command. Open a terminal and type

$ gmic -update

(without the dollar sign). From version 2.7.3 and onwards this will be done automatically when you run

$ gmic

without arguments, according to the main developer of G’MIC, David Tschumperlé.

Gmic offers about the same functionality as the plugin version for GIMP, but it is run from the command line. This opens possibilities that can not be achieved with the plugin version, like batch processing or integration with other command line programs.

To start the program, type the following in the terminal:

$ gmic

(again, without the dollar sign). A demo windows appears. Click on Tetris. Break your personal record. When done hit Esc to exit.

Gmic is a simple photo viewer as well. Type

$ gmic image.jpg

to open a photo called image.jpg that is located in the current directory. A window opens and the photo is shown.

[0] Tour Eiffel-m645-multi-expo.jpg (504x323x1x3)_110

Hit Esc again to close this window. The terminal gives some technical information about what happened. You can ignore that.

Iain’s noise reducer

A noise filter I like and often use is written by Iain Fergusson, a regular contributor to G’MIC. A nice filter but a bit slow, so this is a good candidate for batch processing. The filter is simply called Iain’s noise reduction and in the G’MIC plugin for Gimp it can be found under the Repair entry. The default settings are a bit too much to my taste (but that depends also on the number of pixels of the photo of course and on the scene of the photo). So I adapted the sliders somewhat and added the filter to my favorites (that’s the Faves section on top of the filter list; click on the green plus sign below the filter list to ‘fave’ it with current settings).

In order to apply this filter via the command line to a photo, we must know the filter name plus its parameters. To find this out, start GIMP from the command line by simply typing

$ gimp

in a terminal.

Open a photo, start the G’MIC plugin via the menu Filters – G’MIC… and go to the section Repair, then click Iain’s noise reduction. Choose in the Input/Output field on the left for Output messages ‘Verbose (console)‘. From now on the terminal window shows exactly what happens when you click a button or change a value in a drop down menu in G’MIC.


When you change sliders or values, you’ll see every time a new line in the terminal with the word ‘preview‘ in it. When you click OK, you’ll see a new line with the word ‘apply‘, like in this screen shot.


This looks like crazy terminal prose (it is actually!) but it contains all the information we are looking for. The filter name is ‘iain_iains_nr‘ and the numbers on the right side correspond to the sliders settings and options in the dropdown menus. You can select the relevant (right) part of the terminal output with the mouse and copy it by clicking Ctrl+Shift+C. To paste this selection in a new command in the terminal, use Ctrl+Shift+V.

To apply this filter with these settings to a photo using the command line, we say for example this:

$ gmic -iain_iains_nr 0.613497,9.07975,2,609.756,390.244,0,1,0,0,0,1.35,0,0

The – after the gmic command means ‘use the filter with the following name’.

Of course we need to tell gmic which photo we want to denoise and to what file we want to write the output (for that we use the -o switch, output). Putting everything together we get this:

$ gmic image.jpg -iain_iains_nr 0.613497,9.07975,2,609.756,390.244,0,1,0,0,0,1.35,0,0 -o iainNR.image.jpg

Note: if your files end on JPG, write image.JPG in the command above. Of course most other image formats like tif or png can be used as well – but no raw files.

That line might look intimidating, but it simply says:

$ gmic input -function output


To apply this filter to more than one photo at once, say

for i in *.jpg; do echo $i; gmic $i -iain_iains_nr 0.613497,9.07975,2,609.756,390.244,0,1,0,0,0,1.35,0,0 -o iainNR.$i; done

A file called image1.jpg will be processed and written to a new file called iainNR.image1.jpg, et cetera.

In the next posts about gmic I’ll show you how to use several commands at once, how you can shorten the long command above to something like

$ gmic input my_NR output

and how you can keep the exif info in your photo intact (because, yes, gmic throws that away!). Also on the to-do list is to show how to create your own entry or entries in the G’MIC plugin for Gimp that combines one or more gmic filters and that basically allows you to build your own photo processor. So stay tuned!

Oh, I forgot: the photo on top of this post is one from a series that is batch processed with gmic!