Infrared photos: making things easier

Infrared photos: making things easier

We've gone through the basic concepts, some of the options & parameters & the folder structure for the settings that we might want to use to reuse when we process an infrared or normal photo using the command line tools (dcraw & imagemagick). We've not mentioned exiftool yet, so I'll do that now & then we'll work through the concepts needed to turn a set of termux command line tools into a reasonably friendly system for processing a RAW photo taken through an infrared lens into something that needs just a final tweak before sharing.

Exiftool

ExifTool is a customizable set of Perl modules plus a full-featured
command-line application for reading and writing meta information in a wide variety of files

The important part for us is that it can read all of the EXIF data (such as the date that the photo was taken) & can copy that to the processed image that we'll get out of this processing of the original RAW file.
Using it from the command line to copy the data only needs one line, followed by a bit of clean up (the original processed file is left on the disk when the metadata is added).
You can probably work out what's going on, although it might help to know that the target mentioned is the path+filename of the processed file created by magick, & that the source is the path+filename of the original RAW file.
exiftool -TagsFromFile source target
rm target"_original"

Just one more thing! Android like to be told that there is a new image available. If that doesn't happen then the file will be there, but won't show in the gallery app. Once the RAW file has been processed you'll need to run termux-media-scan target in order to notify the system that there's new photo to see.

Scripting

The aim from here onwards is to make a Termux widget that lauches a termux (bash) script which does the proccessing, after asking for any settings that we might want to specify.
We already created a .shortcutsfolder in the ~ (home) folder of the termux installation. That's where we will put the script. There are a few things to discuss before we get to that though...
Termux-widget: When we have a script created we will be able to launch it using the homescreen widget. To add one simply long press on a blank piece of the homescreen on your phone, choose to add a widget, then pick the termux:widget that you want (the 1x1 shortcut will do fine, but you might want the bigger widget if you use a lot of variations in your processing pipeline.
Passing parameters: You might be familiar with running a command with arguments. Something like exiftool -TagsFromFile source target for example. The problem is that the Termux environment can't really do that via the homescreen widget. With a bit of lateral thinking we can get around that...
Scripts are able to know the name that was used to launch them, so if we can read & parse that - we can use the script's name to tell us what parameters are to be used. It's a feature of linux that you can link "names" to the same script without needing to duplicate the whole thing & rename it. This is done using the ln command.
So, if we have a script called "photo.sh" we can create a set of names that all launch the same script, with each name having the parameters that we want the script to use.
ln -s ./photo.sh ./set_clut.sh when typed from the same folder as the photo.sh script will give us an 'alias' that launches the script photo.sh, but within the script you can retrieve the name used to lauch it by using script_name=$(basename $0) to tell that it was launched using an 'alias' that has the words "set" & "clut" in it. Now we know that a parameter needs to be set, & which one it is.

Practically speaking we'll need to be able to set parameters (to use as a one off, or as the default settings for future runs of the scripts), we'll also want to be able to run the script with the optional "lens" & "clut" if desired.
I've chosen a convention that infrared specific settings are in upper case & settings that could be used for infrared or normal photos are in lower case. There are actually 2 versions of the opts setting (opts & OPTS) because the IR ones don't generally get used in the same way. I've also decided that "set" should be the first parameter in the script name (& that "batch" will be too, when I get to writing that bit)

So, we'll need
photo.sh which is the actual script, but also the name that will process non-IR RAW files using the default parameters (essentially just the "opts" setting).
Links to that file named clut.sh, lens.sh & clut_lens.sh will process a non-IR photo with the default "opts" setting & the relevant distortion & colour mapping (the last 2 are shared with the IR commands, so beware).
Links to photo.sh with "IR" in the name will apply the default OPTS, channel swapping, & hotspot fix (if needed) so these don't need specifying. Which means that we should only need IR.sh, IR_clut.sh, IR_lens.sh & IR_clut_lens.sh to cover our processing needs.
Modifying the default settings is a bit more of a challenge. It is needed before you can use them though - otherwise there are no previous (default) settings to use.
I've assumed that the reason for changing them is that they are going to be applied to a photo, so the settings need to mimic the pattern above. It's simpler to set/review all of the settings than to try to be more selective, but that works if you want a large number of aliases that let you set all of the possible combinations.
set_opts_lens_clut.sh will set & then apply all of the non-IR parameters & leave them as the default for future runs where those parameters are specified.
set_WB_SWAP_OPTS_HOTSPOT_lens_clut.sh will cover everything.
set_WB_SWAP_OPTS_HOTSPOT.sh would cover just the IR specific elements

We've gone through the kind of settings files that you'd put into the folders, but haven't done more than mention the idea of the hotspot fix (image file). That's next.