Using two or more gmic functions to (batch) process photos, making those commands a bit more human readable and how to batch-make ten versions of the same photo with different filter settings is what this post is about.
In a previous post I explained how to process one or more photos using a gmic function via a terminal window. Adding more functions is as easy as adding them to the command we already had.
By doing so, the ‘pipeline’ (the order in which the image is processed) gets like so:
$ gmic input -function1 -function2 -function… output
Let’s say we want to add the sharpness filter called octave sharpener to our command. Like described in the previous article, we must start GIMP again from the command line like so
$ gimp
Next thing is to open a photo (any photo) and start the G’MIC plugin. On the left side we say again under Output messages that we want G’MIC to be verbose and that its output must be sent to the terminal (Verbose (console)).
Now click in the Details section of G’MIC and choose Sharpen [octave sharpening] (a personal favorite of mine). I often set the first slider called Scales to 6 and the second one, Maximal radius, to 4 to reduce the power of the filter because we are working on jpg’s here and those are usually already more or less sharpened in-camera.
The terminal gives the following output:
[gmic_gimp]./preview/ -v -99 -gimp_unsharp_octave_preview 6,4,3,0,11,0,24,0
We copy again the right side, starting at -gimp… Delete that ‘_preview’ part.
The command to reduce noise from the first article on batch processing was:
$ 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
Nota: all the commands on this page are one-liners.
Just paste the octave output from above in the existing command after the noise reduction part. 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 -gimp_unsharp_octave 6,4,3,0,11,0,24,0 -o processed.image.jpg
To batch process a series of photos with both filters, say this:
$ 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 -gimp_unsharp_octave 6,4,3,0,11,0,24,0 -o iainNR.$i; done
Of course we can format the above commands to make things better readable, but we take another approach. Read on.
Organize this please
As you see, the terminal command starts to get messy already and this with two gmic filters only! You can add many more but that will result in near-chaos. Happily gmic offers the possibility to create new and personalized functions. It is as easy as this.
Create a hidden text file called .gmic (on Linux or OS X) in your home directory or a non-hidden file called user.gmic on Windows in the AppData folder. In case you don’t know how to do that: open a text editor and save the empty file with the name .gmic, including that dot before the name.
To place the above noise reduction command (the iain part) into a new function called my_nr, add the following line to .gmic:
my_nr : -iain_iains_nr 0.613497,9.07975,2,609.756,390.244,0,1,0,0,0,1.35,0,0
Save the file. From now on you can use this filter by writing in a terminal
$ gmic input -my_nr output
(Don’t forget the hyphen before my_nr). That looks already better, no? We add the octave sharpener as well to the .gmic file and name it:
my_octave : -gimp_unsharp_octave 6,4,3,0,11,0,24,0
The command to apply both filters to a photo is:
$ gmic input -my_nr -my_octave output
To do this in batch, say:
$ for i in *.jpg; do echo $i; gmic $i -my_nr -my_octave -o gmic.processed.$i; done
Again, if your files end on JPG, write JPG as well in the above command. You can use many image formats. If your images are in tiff or png format, change the above line accordingly.
Different versions? No problem!
Another thing that might be of photographic interest is a command that takes one photo and produces several output files with different filter settings. This might come in handy to find optimal sharpness settings for a certain series of photos for example.
On a Linux pc, open a terminal and write something like:
$ for i in {1..10}; do echo $i; gmic image.jpg -gimp_unsharp_octave $i,4,3,0,11,0,24,0 -o octave.$i.jpg;done
This produces ten photos with the names octave.1.jpg, octave.2.jpg… octave.10.jpg, each with a different Scales parameter (the first slider in the octave sharpener in the G’MIC plugin and the first parameter after the command name), namely from 1 to 10. If you need specific values like 128, 256, 512… then write
$ for i in 128 256 512; do echo $i; gmic image.jpg -command -o filtername.$i.jpg
Oh, I forgot: the photo on top of this post is one from a series that is batch processed with gmic!
pm|jun16