AUTHOR: Ken Moffat - ken@linuxfromscratch.org

DATE: 2016/01/02

LICENSE: Creative Commons Attribution-Share Alike 4.0 International
(CC-BY-SA 4.0)  http://creativecommons.org/licenses/by-sa/4.0/

SYNOPSIS: Using raw photos to get a wider range of highlight and shadow
detail, in a manner somewhat similar to creating HDR photos, but with
8-bit (jpeg) results, and using a comparatively-simple approach.

DESCRIPTION: This guide provides suggestions for using raw photos in the
gimp (2.8) with ufraw so that on-screen jpegs can show more detail, but
without the intricacies of hand-painting masks. The techniques were
tested with pictures of trains, where much detail is often hidden in
deep shadow, but may be useful to people who photograph scenery,
buildings, and other similar subjects, or (untested) for photos of
people in bright sunshine. The approach here is comparatively quick per
photo - real photographers can afford to spend a couple of hours on a
picture, but when I have maybe 50 pictures per day, all of which I want
to try to put online, and a couple of weeks' worth of pictures, such an
approach is not going to work for me.

LANGUAGE: This hint and the menu settings to which it refers use British
English (en_GB), some of the menu spellings might differ in en_US.

PREREQUISITES:

(i). Camera

A camera which takes raw images in a format usable by ufraw
[ http://ufraw.sourceforge.net/Cameras.html ]. The ufraw website is
rather old, I suspect many other cameras are supported, for example my
Panasonic DMC-FZ45 is supported but not listed. For convenience, it is
easiest if your camera can save both raw and jpeg images - the jpegs
will give a first view of what you recorded once you upload them to a
computer and also, at least in my case, provide a more usable subset of
EXIF data. Please note that although ufraw is based on Dave Coffin's
dcraw, it is a rewrite to C++ and therefore released versions will lag
behind new dcraw changes for the very latest cameras.

Unlike "true" HDR photography (multiple exposures, the camera has to be
on a tripod with constant aperture and focus), the approach here uses
*one* image, but applies different exposure values (EV) to it in ufraw,
e.g. 0.00 for what the camera decided was correct, +1.00 (an extra stop)
for a little more shadow detail, -1.00 for highlights. Some people call
this 'Pseudo HDR', others 'Simulated HDR'.

With a good camera, using large amounts of additional ExposureValues to
extract detail from dark parts of the picture is not a problem and a
range of ±2EV on whatever looks like the correct midpoint (often the
same as the camera's 0EV, but occasionally a half or a full stop more or
less) will work well. But with a less-good camera, such as my FZ45,
starting with a fast "film speed" such as iso400, and then adding two
stops (iso1600) or more shows a lot of noise.

For that camera, I have a prefrence for using narrower ranges of EV but
from time to time I need to use more - in those cases, a smaller final
image (e.g. 1600x1200) tends to make the noise less obvious.

In other cases, there is little tonal range, and using ±1EV will get
everything that is on offer. But for views, it is best to zoom-in the
picture in ufraw to make sure that no shadow detail is inadvertently
overlooked.


(ii). Monitor settings and adjustment

Your monitor needs to be adjusted to maximise the range of grey shades
it can display. Some people seem to turn up their monitors to maximum:
apart from hurting your eyes, that is somewhat useless for photo
editing (the "goes up to 11" approach).

If your monitor gives you the option, set it to sRGB. Then, follow the
instructions at
http://www.cambridgeincolour.com/tutorials/monitor-calibration.htm

After that, confirm the setting by reviewing what you see at
http://www.northlight-images.co.uk/viewing.html

My main monitor is a Sharp 20" TFT, using manual Gain Control with both
Black Level and Contrast set to 60 (and using the VGA input). If you do
not have any available controls, and your monitor is too bright (hello,
AOC) you can use xrandr to reduce the brightness. For example I had set
my AOC monitor to 75% brightness with xrandr to avoid hurting my eyes,
but for testing this hint I increased the available tone range by
reducing the brightness a little more in ~/.xinitrc :

 xrandr --output VGA-0 --brightness 0.66

I am not using any colour-correction because my attempts to try the
various available icc profiles (mostly from colord) using xcalib [ from
xcalib.sourceforge.net ] did not show any noticeable differences,
except for three profiles that were clearly not correct for my monitor.
If I ever had a CD for this monitor, I guess I lost it. If I was going
to make a lot of prints, it would be worth getting my screen calibrated
(people speak well of Argyll, with a suitable measuring device) and then
getting a custom icc profile for my printer and paper - I might do that
latter part, apparently you need to use the 'Uncorrected' setting in
'Print with Gutenprint' both when printing the test chart, and when
using the profile.

(iii). A sheet of notepaper with a straight edge.

This is not part of the process, but when I use a wide lens at its
widest focal length I usually see barrel distortion (except on one
really good lens, which is enormous and weighs a tonne). For (some)
buildings, and for trains, this often looks atrocious. Interestingly,
once I notice it, I can often see it in the camera's own jpegs, and of
course I see similar distortions daily in TV news programs and
documentaries, so I guess that many people no longer care. The edge of
the paper can be held against the screen to see if the correction I am
trying is helping things or making them worse. On my FZ45, at some focal
lengths I even see pincushion distortion.

CHANGELOG: 2016/01/02
· Initial version, for comments


WHY:

I got a camera with the ability to take raw images in the early 2000s.
At that time I found ufraw, and used that to adjust some pictures. In
late 2007 I renewed my interest in trains, and model railways, and
started visiting various lines and taking pictures that I hoped might be
useful to other modellers. In the days of real film you could get hand
prints, for a price, with improved detail - the Dodge and Burn tools in
the gimp replicate this approach, but are not easy for a novice to use.

At this time, I was mostly using the curves tools, both in ufraw (a
series of Base Curves I created over the years - some were very weird
shapes) and the curves tool in the gimp to do final adjustments. I was
often concentrating my efforts on extracting the maximum detail (e.g.
in the bogies and equipment beneath a railway vehicle), and I suspect
that from time to time the colours suffered.

That process always seemed haphazard, although on a good day I could fix
up two or three photos per hour. I had become aware of people creating
HDR photos, but I tend to file most of those I see under "everything
overdone". Last year I attempted to get back to preparing photos (I've
got a large backlog, my old process was *really* not working on some
pics from my Panasonic) and seeing if I could find any more-reliable way
to do things. I explored gegl and 16-bit colour, but that did not help
my problems. I also looked again at using layers and trying to blend
multiple exposures, but at that time I failed to get reliable results.

A couple of months ago I resumed this approach, and found some other
links which guided me into what I am now doing. In general, people using
HDR techniques seem to be good at painting masks - I am not, and I
needed something simpler that I could just "apply, see if it works".

My initial attempts seemed to mostly work, but I was not confident of
the process and I made several mistakes. Eventually, I took one set of
pictures where I had not yet attempted to do anything and where some of
the pics came from my Olympus (generally fair quality) and the rest from
my Panasonic (often lower quality, more red noise as I increase the EV,
variable lens distortions). Those pics are from the Zillertalbahn, both
the stock and stations, and also general views. I worked through them
and eventually got them online
[ https://www.flickr.com/photos/61907329@N03/albums/72157659289411903 ]

After that, I took a selection of other photos and worked to finesse the
process. The only pics which actually use my current approach are not
very good (using the Panasonic at iso400 showed up its limitations), but
they are probably as good as I'm going to get:
[ https://www.flickr.com/photos/61907329@N03/albums/72157662818676856 ]


DRAWBACKS:

The main drawback is that this approach reduces the contrast. After
finishing my first set of pictures, I explored alternative approaches.
The only thing which reliably improved the result was to increase the
contrast - but at the expense of losing some of the hard-won shadow
detail.

In one picture (a red train mostly in shadow, everything else in full
sun) the red came out a bit magenta-ish or blueish. I eventually got an
adequate result by increasing the base exposure a little more and
sacrificing one highlight (a white cloud). So, this is not a panacea,
and for some photos I have ended up spending a long time trying
different settings.

If the EV needs to be boosted, particularly at high ISO numbers ("film
speeds"), the amount of sensor noise can become obtrusive, at least on
my Panasonic.

The biggest drawback is that, as with my previous approach, when things
are going well I can still only do 2 or 3 pictures per hour, and often
fewer, but at least the process is now more repeatable.


INSTALLATION:

The gimp (2.8.16) is in BLFS (I initially tested with 2.8.14 from BLFS
7.8, for this hint either version is fine) - I assume that the libexif
dependency is needed to write some EXIF data (that functionality is new
in recent versions of gimp-2.8, and will cause you surprise if you did
not know it was present).  There are two necessary additions, one plugin
(Advanced Tone Mapping) and the ufraw package. So, after the gimp has
been installed, first get the plugin from
http://registry.gimp.org/node/5980
(open in a browser, download the attachment and read the notes and
follow the link to the blog post).

As root,
install -v -m644 /path/to/advancedtonemapping.scm \
 /usr/share/gimp/2.0/scripts [ yes, 2.0 not 2.8 ]

For me ufraw-0.22 is just a straight ./configure --prefix=/usr
followed by make, and then as root make install.

This uses, and probably requires, jpeg(-turbo), libtiff, and libpng. It
also needs exiv2 to read the EXIF (and XMP) Metadata. It can apparently
use libjasper (I do not build that). All of those are in the BLFS book.

I do not provide the deps for CFITSIO and LENSFUN : lensfun is a
database of lens variations, I tried it when ufraw could first use it,
but did not see any benefit on what I was doing at that time. I thought
it had become non-free (as in 'paid for'), but I see it is currently at
https://sourceforge.net/projects/lensfun/ and uses cmake. Perhaps it is
useful to correct lens abberations, if your lens has been reliably
measured. I know nothing about CFITSIO (according to wikipedia it is for
processinging astronomical science data), but it is at
http://heasarc.gsfc.nasa.gov/fitsio/ if you have any need for it.

There are a number of configure options in ufraw, but I do not need to
use any of them - please check them in case they apply to your camera.


HOW TO USE IT:

At last, the rules of thumb I use for processing the pictures!

1. Configuring the gimp to support this process.

1.1 In the gimp, ensure that the Layers dialog is visible. If it is not,
go to Windows -> Dockable Dialogues and click on Layers.

1.2 Remember that you can always undo, and for filters you can undo/redo
if you were not sure about the effect and wanted to see it happen again,
or more usually (trying different settings) undo/reshow [ that will
leave the values as you last used them, you can then adjust them ]. The
default undo settings are too restrictive for this process (you probably
never need to be able to go all the way back, but allowing that can be
useful). The default seems to be 5 levels of undo, and since add new
layer, paste, anchor, duplicate, desaturate, invert, select all, add
layer mask, paste, anchor, delete layer each count as one level, 5 is
woefully inadequate. For what I am doing, 25 levels might be enough, but
30 seems safer. Unfortunately, the undo history is never saved. So,
whenever you are making a *series* of changes which might need to *all*
be backed out (rotate/perspective/crop) or Contrast with Advanced Tone
Mapping (below), it is best to save the xcf file before you start the
series of changes, and then not save it again until the series is
completed and you are happy that it is ok. Some of the gimp's settings
need to be changed to allow more undo levels, and you might also want to
display the Undo History dialogue (Windows -> Dockable Dialogues -> Undo
History). To change the settings for Undo, go to Edit -> Preferences ->
Environment :

1.3.1 increase the Minimal number of undo levels to 25 or 30

1.3.2 for Maximum undo memory, mine defaulted to 64MB. I found a
suggestion that 2 or 3 GB might be needed, and another that using 3GB
slowed a machine (probably 32-bit) to a crawl. I have at least 3.9GB of
RAM on my machines, so for the moment I have set this to 512MB and it
seems to be sufficient - my largest pictures are only 4336x3258 pix. I
guess larger images might need more undo memory.

1.3.3 The Tile cache size defaults to half the available RAM, but with a
size measured in KB. I see no reason to change this on my machines.

1.3.4 The Maximum new image size on this machine was 128MB, there is no
need to change this - if you try to create a bigger image, it will ask
if you wish to do that.

1.3.5 In Preferences -> Folders, the default Temporary folder is /tmp,
but the Swap folder is ~/.gimp-2.8 : in practice, this is where
everything seems to be stored. My images are all in ~/ so that seemed
fine, except on my test machine where /home is woefully tiny: for that,
changing the swap folder to live in /tmp worked well.

2. Configuring ufraw : from within the gimp, open a raw file. You will
see a lot of options at the left:

2.1 The exposure EV is the most obvious (you can overtype in the box to
set a value, or delete everything to restore to 0.00)

2.2 next to this is an icon to change how details are restored for
negative EV - I use the upright lightbulb setting to restore in LCH
space for soft details

2.3 then there is an icon for how highlights should be clipped in
positive EV space - I use what the tooltip describes as 'soft film like'
but I cannot say what the icons are supposed to represent ;)

2.4 Next to this are icons to auto-adjust the exposure (never useful,
IMHO) and to reset it to the default.

Below these are icons for:

2.5 white balance (I usually use the camera's) : if you ever need to
change this, e.g. for indoor shots, remember to use the same setting on
all three exposures, then go back to the camera's own white balance for
any other pictures.

2.6 greyscale mode (not relevant)

2.7 curve - set this to linear, i.e. a straight line from bottom left to
top right

2.8 profile - I have no profiles, so I set the Input ICC Profile to No
Profile, without a profile I use the default Gamma and Linearity, Output
Profile sRGB, Output Intent set to Perceptual, Output bit depth 8 (jpegs
are only 8 bit, although you can create pngs or tiffs as 16-bit if you
wish - camera raw files typically have 12 or 14 bits of actual data),
Display Profile set to System Default, Display intent set to Perceptual
NB if you use 16-bit, the gimp's xcf files will be bigger!

2.9 Saturation - use a Linear Curve

2.10 Lightness Adjustments - no idea, this just shows an eyedropper

2.11 Crop and Rotate - ignore

2.12 EXIF data summary, as read by exiv2.  This is useful to help decide
what, if any, lens correction is likely to be needed.

2.13 You will also need to be able to identify overexposed areas (i.e.
those parts which eventually become burned out): Open a raw image. Under
the histogram, right at the bottom, are two check boxes to identify
overexposed and underexposed areas. Check the box for overexposed
areas (only) - they will start to flash. If nothing is flashing,
increase the exposure adjustment (EV) until you see what happens. For
underexposed areas, I rely on my judgement.

3. Begin the process: open the image at three different EV settings.

In the gimp, open the raw photo you wish to work on. This will open the
ufraw plugin. You may wish to make a note of the EXIF data for focal
length and aperture. On a good camera, any lens distortion should be
consistent for a given focal length and aperture. With enough pictures,
it is therefore possible to keep notes and determine the expected
correction to use.

3.1 Begin by deciding what is a mid-tone in the shot, and adjust the EV
until that part looks correct. In many, but not all, shots the camera's
own idea of the EV (0.00) will be correct. Conversely, when trying this
technique on some pics from an older camera (Olympus E500) I found that
in most cases it appeared to underexpose by a half or a whole stop. So,
know your camera! Usually I begin by moving in ±0.5EV steps to see how
things change, but sometimes I end up trying ±0.25EV changes. In general
I cannot say that any particular exposure is "right", only that it seems
plausible.

3.2 You now have the "base" exposure. Before you open that, work out
what range of exposures you want to use, both to recover shadow detail,
and to ensure that the highlights are not blown out.

If there is very little detail in the shadows, perhaps +1.0EV (on top of
the base exposure) will suffice. In other cases, +2.0EV and occasionally
even more will give you more detail.

Then look at the highlights - the image in ufraw will "sparkle" or
"twinkle" for anything that the program considers is burned out. Mostly,
I find that a small reduction in exposure, often only -0.5EV, is
sufficient to stop that.

The problems are where the highlights need a larger reduction than the
increase for the shadows - in these cases, your base exposure might need
to be adjusted. Also, if the main subject is dark (e.g. a dark green
railway carriage) the final end result might appear too light, in which
case you will need to come back to this stage and try with different
values. In such cases, it may be better to make the base EV slightly
darker (underexposed) than you would otherwise use, and perhaps also to
restrict the range (e.g. ±1EV instead of ±2 EV) so that the final colour
is not too light. If the picture is underexposed, using a large range of
EV adjustments might make sensor noise (from the EV used for shadow
detail) too prominent - if that happens to you, see whether a different
base EV, and a smaller range, will help.

3.3 The critical thing, IMHO, is that the shadow and highlight EV
changes match, to avoid odd colour changes. So, if the shadows need +2.0
EV on top of the base exposure, I will use -2.0 EV off the base for the
highlights.

3.4 In some shots, the raw image at the base EV has little or no
overexposure. Such shots may limit your ability to use wide EV ranges
because almost nothing will be taken from the highlights image. If that
happens, I suppose you could try a brighter highlights exposure (i.e.
not a central base exposure).

3.5 I have tried using layers copied from the *base* exposure to create
masks in some pictures, but I found the process much harder (keeping
track of the right layer) and not reliably better.

3.6 Always check your maths, particularly if you are not using 0EV as
your base. e.g. For a base exposure of +0.25 EV, and a range of three
stops (total), you need shots at +0.25EV, +1.75EV, and -1.25EV (±1.5
stops).

3.7 Now open the picture three times at the desired exposure variations.
I find it easiest to open the darkest (highlights), then the lightest
(shadow) and finally the base. For me, the gimp opens comparatively
small windows for each image, which is good for easily getting to any of
them, and also allows me to have one or two others open as well. To help
you understand the effect of the changes, you might wish to open a
second copy at the base exposure, so that you can later compare the
multi-layered version. If you do that, it is best to save the working
copy (filename.xcf, or filename-something.xcf) to prevent you from
accidentally saving the unaltered image over it [ doing that is probably
NOT undoable ]. You might also want to open the camera's own jpeg
(assuming you have one) for comparison.

3.8 I normally save my "working" copy as filename-fixups.xcf, this
contains all the steps *except* for the Unsharp Mask. I then create
filename-prepared.xcf, apply the Unsharp Mask, and then export a jpeg to
filename-90.jpg to review. The -90 is because I use the default 90%
compression, and avoids overwriting the camera's own filename.jpg.

If I make multiple attempts at a picture, the second will be
filename-fixups-A.xcf, then -B, etc.

3.9 Perhaps I need to mention here that the working files can be
somewhat large: on one sample photo from my panasonic [ 4320x3240 pixels
before cropping ] the camera's own jpeg is only 4.7M, but a multilayer
xcf file was 137M and the xcf files before and after sharpening were 47M
and 46M. My 90% jpg took 7.1M. To save space, I use bzip2 to compress
the xcf files after I'm done. The gimp can open the .bzip2 (or, indeed
.xz, but I find bzip2 quicker and the space difference is not major).


4. Add the shadows to the main image.

4.1 In the window containing the base image, go to Layers -> New Layer
and add a layer. I normally call my layers 'shadow' and 'highlights'. If
you forget to change the name, you can click on it in the Layers dialog
and edit it there.

4.2 Now, go to the shadow image.
Select -> All and then Edit -> Paste

4.3 Go back to the base image, in the Layers dialog you should see that
you are in 'shadow'. Edit -> Paste : the Layers dialog will show a
Floating selection at the top. On the bottom of the Layers dialog, next
to the rightmost icon for delete (variously a red ring with a black x in
it, or a dustbin, depending on your icon theme) is a representation of a
ship's anchor. Click on that to anchor the paste.

4.4 You now have the shadow layer visible in the main image window, i.e.
the picture has all become lighter. The next step is to make a mask so
that some of this (the bright parts) will not be so bright. In the
Layers dialog, right-click on the shadow layer, and select 'Duplicate
Layer'. You should now have a layer called 'shadow copy' (temporarily,
3 layers). This is where you will need to take things on trust for a few
minutes.

4.5 A layer mask is monochrome (black, white, shades of grey). Anything
within it which is white will be wholly visible, anything black will not
show at all. We begin by using Colurs -> Desaturate. There are options,
I use the first (Lightness), and you need to click on 'OK'. At this
point, you have a black and white photo, and because this is the most
exposed layer, a lot of it may be fairly pale. But what we need here are
the dark bits.

Click on Colours -> Invert : what was dark should now be white or light
grey. Now Select -> All and Edit -> Copy to copy the mask.

4.6 Now go back to the Layers dialog. Right-click on the shadow layer
and Add Layer Mask. There are options, but I think for this process any
of them will do, so just 'Add'. The active (coloured) line in the Layers
tab should now be on the shadow layer, and it will now have an empty box
to the right of its first ('picture') box.

4.7 Go back to the main image window, the Layers dialog shows you are in
the shadow layer and you still have the inverted mask occupying the
window. Edit -> Paste. Go to the Layers dialog and anchor the floating
selection. Nothing seems to have changed, except that anchoring that
paste put something into that new box (the mask). Now click on the
shadow copy layer (top of the stack in the layers box) and then click on
the delete icon (at the right end of the icons) to delete it.  You are
now back to 2 layers (initial, and shadow).

4.8 If this worked, the darker parts of the original image should now be
lighter, so with more detail, but any overexposed highlights will still
be blown, and the whole image may have become a bit lighter. If your
results are different, stop, see if you can work out what you did
wrongly, and if not work through Edit -> Undo until the problem is
apparent.

4.9 At this point, you can go back to the overexposed image and Edit ->
Undo : if you undo 'Select All' you can now close that image without a
dialog asking if you wish to save the changes.


5. Add the highlights (much as before, but no inversion)

5.1 In the main image Layers -> New layer : I call it highlights.

5.2 In the dark image, Select -> All and Edit -> Copy

5.3 In the main image (the Layers dialog should show 3 layers, and you
should be in the top one, 'highlights') Edit -> Paste and then in the
Layers dialog click the anchor. The main image should now match the dark
image, i.e. most of it is too dark.

5.4 In the Layers dialog, right click on the highlights layer and select
Duplicate Layer so that you temporarily have 4 layers.

5.5 Go back to the main image window, the Layer dialog will now show you
are in 'highlights copy'. As for the shadows, use Colour -> Desaturate
and click 'OK'. This time, we want the highlights to appear white in the
mask, and that is how they will be, so do NOT invert the colours.

5.6 In the Layers dialog, right click on the highlights layer, select
Add Layer Mask, click on Add.

5.7 In the main image window, Edit -> Paste. In the Layers dialog,
Anchor the floating selection, then click on the top layer (the copy)
and delete it.

At this point, you should have three layers, with shadow detail and
highlight detail all present in the picture. But the contrast will have
been reduced.

You can also dispose of the underexposed shot that you used for the
highlights by undoing Select All and closing.

The process to this point used judgement to select the exposures, and
then a mechanical application of the steps to add and mask the layers.
>From here on, just as when you work on a single exposure, you are back
to using your judgement, so do not rush.


6. Corrections (this part is not specific to using multiple exposures)

>From here, you probably want to make the image window occupy most of
your screen - I normally have several terms open (notes on what I'm
doing, notes on typical distortion values to use with my lenses) and of
course the gimp provides various tabs. You may prefer to just maximize
the image window.

At certain focal lengths, I need to mitigate the lens distortion. In
some pictures, I need to correct rotation (clockwise / anticlockwise)
and/or tilt because the camera was pointing up or down (perspective).
Attempting to correct any lens distortion needs to be done first, before
any attempt to straighten the picture. NB both rotation and perspective
can be done with the perspective tool, but I find it easier and quicker
to do them separately.

6.1 Click in Layers -> Merge Down, twice, so that your three layers are
reduced to one layer.

With some of the filters and tools (lens distortion, perspective,
rotate), if you try to use the tool when multiple layers are present the
preview will be in monochrome. For other filters such as the unsharp
mask, working on multiple layers will appear to work, but have less
effect than expected. So, always check that you have merged down all the
layers. If you try to use the Advanced Tone Mapping filter on multiple
layers, it will fail and corrupt the Undo history.

6.2 Now, if needed, do any lens correction

The filter is at Filters -> Distorts -> Lens Distortion. I only ever
change the top field (Main). If you can see barrel distortion, use a
negative number here (very specific to the individual camera / lens).
This is where the sheet of paper comes in, you can lay it on your screen
along any line which *ought* to be straight, and watch how the curvature
changes at different settings.

If you started with barrel distortion, a negative value in 'Main' will
push the corners of the image out, and you will still have pixels in the
full image area. But if you started with pincushion distortion (much
less common), a positive value in the Main field will push the corner
pixels in and you will no longer have anything in the corners of the
image, or perhaps at the edges. That will be addressed at 6.5 ('Crop').

6.3 Rotation

>From time to time, I take a photo in a rush. Sometimes, the result is
useless, e.g. the subject wasn't in focus. Other times, it looks as if
it might be useful, but things are all at an angle. It can be hard to
distinguish rotation from perspective distortion in some pictures. I
usually find that separating Rotation and Perspective orrection makes
things easier, but YMMV.

Tools -> Transform Tools -> Rotate gives you a dialog where you can set
the angle, and a grid over the picture. In practice, what matters is the
central part of the image, around the cross marking. To check verticals
(and horizontals if present), I pull the dialog around so that I can use
its edges to review what I can see. To zoom into the picture, click on
the main image amd then '+' (as many times as necessary), or '-' to zoom
out again.

If the whole shot is rotated, enter the number of degrees (positive
rotates clockwise) on the dialog, then enter. I normally use multiples
of 0.5°, that seems to usually be close enough. And note that if you
have to rotate more than about 2°, a lot of the picture will be lost.

6.4 Perspective

The archetypal problem for perspective distortion is converging
verticals on high buildings. Nowadays, my common problem is the
opposite - I tend to have the camera pointing very slightly down, so
that verticals at the edge of the picture spread out towards the edges
(walking with two sticks makes me look down). In either case, this can
be fixed with Tools -> Transform Tools -> Perspective. This tool can be
a bit fiddly to use [ you get numbers on a popup, but they are not
useful], and although I have tried pulling corners out (to spread the
pixels) there never seems to be enough screen space to do that.  I find
the easiest way to fix the problem is to slide the corners of the grid
inwards (left-to right, NOT up or down) to correct the problem.

6.5 Crop

If your image no longer occupies the full image area, you will need to
crop it. Alternatively, you might anyway want to crop it, either to
exclude someting, or to just provide a different format (e.g. simulated
widescreen or 'letterbox' from a normal camera). I take four-thirds
photos, for these the ratio should be 1.333 for landscapes, or 0.75 for
portrait (vertical) images. For other aspect ratios, you will need to
work out the ratio for yourself. The bottom of the window SHOULD show
the ratio (but only to 2 decimal places) when the crop tool is in use.
But occasionally, it doesn't. If that happens to you, save the xcf
without cropping it, close the gimp, then open the gimp, open that xcf
file again and retry. To crop, click in one corner of the part you wish
to retain, then pull the mouse to the opposite corner, checking the
ratio. Move the edges of the crop inwards if necessary (e.g. to retain
the ratio).

When ready, check that you did not include an empty part of the image
(chequered background) within the crop, and then click within the crop.


7. Improving the picture.

There are now two or three things which you might wish to try.

7.1 If you feel a need to change what is in the picture, using either
the clone or heal tools, take a copy, work on that, and ideally save it
to different names at frequent intervals. Some people are naturals with
these tools, I'm not. I have tried to use the clone tool to paint over
burned out rivet heads on a light green shiny sunlit surface, and
eventually managed, but I found it easy to do too much - if I realised
immediately, I could undo, but if I did not notice until a minute or two
later the bad change was too long ago to undo.

7.2 The first general improvement is to increase the contrast using the
bottom slider in Colours -> Brightness-Contrast (range -127 to +127). In
particular, this can sometimes make colours look more realistic. The
problem is that increasing the contrast can lose all the hard-won shadow
detail. At the moment, I am usually increasing the contrast to between
13 and 25, or occasionally 39. For the Zillertalbahn picture mentioned
above, I did not do this. But do NOT save the file here, in case the
gimp crashes before the next step and you cannot undo it.

Alternatively, if you are experienced in using the levels tool, I guess
you can adjust the values in that. When I first began working on single
exposures, I saw many recommendations to use the Levels tool : sure, it
gave very bold high-contrast images but the results were not what I was
looking for, so I now avoid it.

7.3 The other improvement is the Advanced Tone Mapping plugin ('ATM').
The version installed above works with gimp-2.8 (I previously found an
older original version that did not). It can be found at Filters ->
Enhance -> Advanced Tone Mapping. In many cases, the effect seems to be
minimal, but in some it definitely helps make the picture look more
alive. In general, it also reduces the contrast a bit.

There is a dialog for altering the settings (see the blog entry linked
from the gimp registry for more details of why to do this) but I always
leave it set to the defaults. Using this adds a new layer, so you should
merge down afterwards [ if you don't, things like the unsharp mask still
seem to work, but perhaps not as well as they ought to ]. Again, if you
try this filter on an image with multiple layers, it will break the undo
history.

If you are using both added Contrast and Advanced Tone Mapping, it might
need several attempts to find a good combination: set the Contrast,
perhaps a little more than you think is right, then do the ATM. If too
much shadow is lost, undo both steps and try again with different
Contrast. Similarly, try with more contrast if it is too light after
doing this. In a few cases, avoiding the ATM filter has seemed the best
bet, but for the moment I do not have a theory for when to use it ot not
use it.

7.4 When I started out with single images, I used to use the Curves tool
to get more detail out of some pictures, particularly underframe or
chassis detail on trains. With my current approach I had hoped to avoid
having to do that, but in a few photos it might still be useful. If
needed, I suppose this ought to be done before playing with Contrast and
ATM, but in practice that means trying without and then reverting,
playing with the curve, and trying again, or just doing it last.
Hopefully you will not have to use the curves tool very often.


8. Final sharpening.

The amount of sharpening to use depends not only on the picture, but on
the intended use: prints will require more sharpening. The tool is at
Filters -> Enhance -> Unsharp Mask. I normally begin with a Radius of
5.0 (the default) and an Amount of 0.90 (instead of 0.50). I have never
found a reason to put a value into the Threshold box. While testing this
procedure on some pics from an older camera (Olympus E-500), I found a
greater sharpness (5/1.0 or 5/1.2) was helpful - even though the picture
was apparently correctly focussed and not taken on the move.

For some pictures (those which are intrinsically less sharp, either
where the camera was moving, or because it was focussed on the wrong
place), a slightly larger Amount (up to 1.2, for example) sometimes
helps. But with sharpening for online use it is important both to zoom
in to look at the datails, and to zoom out to get a view of the whole
picture.

In a few cases (haze) a larger Radius can be useful (try 15, see what
changed, then use smaller or larger). The danger is that other parts of
the picture might be over-emphasized, or you might get odd effects with
higher values. With all the tools, but particularly with the unsharp
mask, by the time you can see the effect you have overdone it.

If you are printing on paper you probably want a different aspect ratio.
The A range of papers (usually A4 for inkjet photo paper) have an aspect
ration of 1.1414 (210:297). For prints, I take the prepared but
unsharpened image, save it to a new name, crop towards this ratio, and
then apply a stronger sharpening.


9. Creating a jpeg.

At this point, the image is still only in an xcf file. You can make a
jpeg from the File -> Export menu (until I took this multilayer approach
I was often forgetting that 'Save' is now only used for xcf files, but
now the separate Export seems natural to me :)

Change the suffix to .jpg from the default .png if this is the first
export in this session. I like to make the name whatever-90.jpeg so that
if the name matches the camera's name it will NOT overwrite the camera's
own jpg. For a jpeg, the next box allows you to set the quality, with a
default of 90. A quality of 90 (%) seems to be adequate, at least on my
20" screen or on A4 prints.

That's it!


OTHER USEFUL PACKAGES:

1. Image::ExifTool is just a perl module, stable versions are at CPAN.

Most of what I have put online has included all the original EXIF data
from the camera, even though my pics are resized. It annoyed me
intensely to put up a pic claiming to be 3970 pixels wide when it was
actually only 1400 pix (yes, I get anal about this sort of thing - I
assume most LFS users do too ;)

There are a number of links for how to hide *all* EXIF data, but fewer
examples for just removing what is now wrong. Also, recent versions of
gimp-2.8 have started to write _some_ EXIF data into jpegs. That was a
bad surprise until I understood what was happening (I had a script from
the past which added EXIF data from the original image, and now there
was extra and inconsistent data).

At the moment, I am continuing to resize images to fit on _my_ screen -
see below - although there is probably no need to do that for flickr if
the picture is of good quality. I use a script to add EXIF data to the
small pics [ now I'm taking the EXIF data from the jpeg, which has fewer
fields than the raw files ] and I use the following command to get the
fields I want to use. Ideally, I would also show the lens details for
the Olympus, but I have not managed that. I hope the following is
sufficiently self-explanatory:

        exiftool \
         -all= \
         -Tagsfromfile ${MASTERDIR}/${FILEROOT}.jpg \
         -overwrite_original \
          -ThumbnailImage= \
          -UserComment= \
            -Make \
            -Model \
            -DateTimeOriginal \
            -ExposureTime \
            -FNumber \
            -ISO \
            -FocalLength \
            -LensType \
           "-copyright<=${COPYRIGHT}" \
            "-comment<=${MYCOMMENT}" \
              -m ${FILEROOT}-screen.jpg

 Partial explanations:
  -something= : remove this identifier (so, begin by removing *all*
   fields). This has to come first.
  -Tagsfromfile : where to get the EXIF data, the camera's own jpeg
  -Overwrite_original : in this context, overwrite MY file instead of
   copying it.
  -Make -Model etc : without '=', specify the fields to copy.

 I have previously set $COPYRIGHT and $MYCOMMENT to point to files
 which contain my claim of authorship, year, and the license, or a
 brief description of the subject - for trains, usually just a general
 comment such as "taken on the fubar railway".


2. ImageMagick is in the BLFS book. My own photos are larger than my
monitor, so to check what I have done I copy the jpeg to a directory set
aside for small images, then reduce it with the 'mogrify' command, e.g.

 mogrify -resize 1200x900 filename.jpg

This is for photos keeping an approximately four-thirds format, it ensures
that the resulting image is never larger than 1200x900 (which fits on the
screen of the machine where I mostly do this). If the photo is in portrait
mode (i.e. vertical) it will restrict it to about 675x900. I then use the
display command to check that I have not done something silly.


FURTHER READING:

1. What really got me started on this current method was
http://iffles.com/2010/03/11/faking-hdr-in-gimp/ although I only use the
first parts of that - as far as 'Well, more of the photo is exposed
properly now, I guess, but it still doesn’t “pop” like I want it to.
Note: This is where my tutorial differs from the instructables one.'

2. From that, I looked at the instructables reference -
http://www.instructables.com/id/HDR-photos-with-the-GIMP/ - I note that
this does NOT make the masks from the same layer, and uses the Curves
tool for the example image.

3. A Book, GIMP 2.8 for Photographers (I purchased my copy as a PDF from
http://shop.oreilly.com/product/9781937538262.do ) sections 3.16.3-4,
pages 286 - 294 in my copy - the example uses three png files, and seems
a lot more involved than my simplistic approach.

4. For an alternative introduction to (true) HDR, using different tools,
see e.g. http://photoblog.edu-perez.com/2009/02/hdr-and-linux.html

5. For an interesting review of raw processors and image formats, see
http://ninedegreesbelow.com/photography/linux-raw-processor-review.html

6. For somebody else's examples of psudo-HDR (using Photomatix Pro - a
non-linux commercial program), with a comparison to the original single
shot and with discussions of the whole idea, see
http://www.cambridgeincolour.com/forums/thread420.htm

7. For a long document on colour management and related issues, see
https://docs.kde.org/trunk4/en/extragear-graphics/digikam/raw-decoding.html

