Simple Exposure Mapping in GIMP


Simple Exposure Mapping in GIMP

A simple approach to blending exposures

There are many different approaches to blending exposures in the various projects, and they can range from extremely detailed and complex to quick and simple. Today we’re going to look at the latter.

I was recently lucky enough to attend an old friends wedding in upstate NY. Mairi got married! (For those not familiar with her, she’s the model from An Open Source Portrait as well as A Chiaroscuro Portrait tutorials.)

Mairi Chiaroscuro Portrait
Mairi’s chiaroscuro portrait.

I had originally planned on celebrating with everyone and wrangling my two kids, so I left my camera gear at home. Turns out Mairi was hoping that I’d be shooting photos. Not wanting to disappoint, I quickly secured a kit from a local rental shop. (Thank goodness for friends new and old to help wrangle a very busy 2 year old.)

During the rehearsal I was experimenting with views to get a feel for the room I’d have and how framing would work out. One of the shots looked from the audience and right into a late afternoon sun. My inner nerd kicked in and I thought, “This might be a neat image to use for a tutorial!”.

Exposure Fusion (Mapping)

The idea behind exposure fusion (or mapping) is to extend the dynamic range represented in an image by utilizing more than one exposure of the same subject and choosing relevant bits to fit in the final output.

I say “fit” because usually you are trying to put a larger amount of data than a single image might have been able to capture. So you choose which parts you want to use to get something that you’ll like. For example, here we have two images that will be used in this article where the image showing the foreground correctly causes the sky to blow out, while exposing for the sky causes the foreground to go almost black. By selectively combining these two images, we can get something that might show a larger dynamic range than would have been possible in a single exposure:

This porridge is too hot, this porridge is too cold, but this porridge is just right.

This is one common use case scenario for creating HDR/EXR imaging (and tonemapping is the term for doing exactly what we’re describing here - squishing data into the viewable range in a way that we like). In fact, at the end of this article I’ll show how Enfuse handled merging these image exposures (spoiler: pretty darn well).

Exposing

In exposing for the subjects in this image, I used the structure to block the sun from direct view (though there’s still a loss of contrast and flaring). The straight out of the camera jpg looks like this:

Foreground Exposure
Foreground exposure

This gave me a well exposed foreground and subjects. I then gave the shutter speed a quick spin to 11000 (about 4-stops) to get the sky better exposed. The camera jpg for the sky looked like this:

Sky Exposure
Sky exposure

In retrospect I probably would have been better to shoot for 2-stops difference to keep the sky exposed higher in the histogram, but c’est la vie. It also helps to avoid going too far in the extremes when exposing, so as to avoid making it look too unrealistic (yes - the example above probably skirts that pretty close, but it’s exaggerated to make a good article). This gives us a nice enough starting point to play with some simple exposure mapping.

Alignment

For this to work properly the images do need to line up as perfectly as possible. Imperfect alignment can be worked around to some extent, usually determined by how complex your masking will have to be, but the better aligned the images are the easier your job will be.

As usual I have had good luck using the align_image_stack script that’s included as part of Hugin. This makes short work of getting the images aligned properly for just this sort of work:

/path/to/hugin/align_image_stack -m -a OUT FILE1 FILE2

On Windows, this looks like:

c:\Program Files\Hugin\bin\align_image_stack.exe -m -a OUT FILE1 FILE2

Once it finishes up, you’ll end up with some new files like OUT0001.tif. These are your aligned images that we’ll now bring into GIMP!

Masking

The heart of fusing these exposures is going to rely entirely on masking. This is where it usually pays off nicely to take your time and consider carefully an approach that will keep things looking clean and with a natural transition between the exposures.

If this had simple geometry it would be an easy problem to solve, but the inclusion of the trees in the background makes it slightly more complex (but not nearly as bad as hair masking can get). The foreground and sky are very simple things to mask overall, where we know we may want 100% of the foreground to come from one image, and 100% of the sky from another. This helps simplifies things greatly.

Rough Mask Example
Rough mask (temporary - for reference only) where we can see we want all of the sky from one image, and all of the foreground from another.

I tend to keep the darker sky layer on the bottom and the lighter foreground layer above that.

The hard edges of the structure make it an easy masking job there, so the main area of concern here is getting a good blend with the treeline in the background. There are a couple of approaches we can take to try and get a good blend, so let’s have a look…

Luminosity (Grayscale) Mask

A common approach would be to apply an inverted grayscale mask to the foreground layer. If there’s a decent amount of contrast between the foreground/sky layers then this is a quick and easy way to get something to use as a base for further work:

GIMP Add Layer Mask Dialog

Applying this mask yields pretty good looking results right away:

GIMP Inverted Grayscale Mask

You can also investigate some of the other color channel options to see if there might be something that works better to create a clean mask with. In GIMP 2.9.x I also found that using Colors > Components > Extract Component using CMYK Key produced another finely separated option.

This makes a nice starting point. As we said we wanted all of the sky from one exposure and the rest of the image from the other exposure, we can start roughing in the overall mask.

For this simple walkthrough we can make our job a bit easier by using two copies of the foreground layer and selectively blending them over the sky layer.

Why Two Layers?

If you take your foreground layer and start cleaning up the mask for the sky by painting in black, it should be relatively easy. Until you get down to the treeline. You can use a soft-edged brush and try to blend in smoothly, but in order to let the sky come through nicely you may find yourself getting more of the dark exposure trees showing through. This will show as a dark halo on the tops of the trees:

A nice way to adjust the falloff along the tops of the trees is by using a second copy of the foreground layer, and using a gradient on the mask that will blend smoothly from full sky to full foreground along the tops of the trees. This will ease the dark halo a bit until the transition looks good to you. You can then modify/update the gradient on the copy until the transition is smooth or to your liking.

At this point my layers would look like this in GIMP:

GIMP Layer Stack Blending

The results of using a second fore layer with a gradient to help ease the transition:

Top: Original grayscale mask only
Middle: Manual mask painting down to treeline
Bottom: Second layer with gradient mask

When pixel-peeping it may not seem perfect, but in the context of the entire image it’s a nice way to get an easy blend for not too much extra work.

Left: Grayscale mask, Right: final mask with gradient

At this point most of the exposure is blended nicely. The only place in this particular image I would work some more would be to darken the structure a little bit to lessen the flaring and maybe bring back a little darkness.

This can be accomplished by painting over the top mask. I used black with a smaller opacity of around 25% to paint over the structure and allow the darker version underneath to show through a bit more:

Left: gradient masked, Right: structure darkened slightly to taste

Enfuse Comparison

I have previously used Enfuse and gotten great results even more quickly. For comparison here is the result of running Enfuse against the same images:

Left: Manual masking result, Right: Enfuse automatic blend

I prefer our manually blended result personally, but I could see another future article or post about using the Enfuse blend for areas of complexity and blending the Enfuse output into the final image to help. Might be interesting.

(I prefer our blended result because Enfuse considered extremely bright areas as candidates for fusion with the other exposure - so the bricks and tent highlights got pushed down automatically.)

Fin

From here any further fiddling with the image is purely for fun. The two versions of the image have been merged nicely. If you wanted to adjust the result to not appear quite as extreme you could modify each of the layers to taste.

For instance, you could lighten the sky layer to decrease the extreme range difference between it and the foreground layer. Where’s the fun in keeping it too realistic though? :)

For reference, here’s my final version after masking with a bit of a Portra tone thrown in for good measure:

Final version with portra color toning
Not bad for a relatively quick approach.

Resources

This wouldn’t be complete with some resources and further reading for folks!

I have saved the GIMP 2.9.x .XCF file I used to write this. It has all of the masks and layers I used to create the final version of the image:

Further Reading

@McCap also created a YouTube video walking through how he approached exposure blending:

The image Wedding Rehearsal by Pat David is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Permissions beyond the scope of this license may be available at https://patdavid.net/about.


This is a companion discussion topic for the original entry at https://pixls.us/articles/simple-exposure-mapping-in-gimp/
7 Likes

Great tutorial, Pat! I agree that the manual blend looks better, mostly because the contrast of the people and the shining concrete pad they are standing on. The sky, however, looks really good in both of them! Doesn’t Hugin employ enfuse when fusing exposures from stacks? Can one potntially use the masking features in Hugin to mask out areas when exposure fusing stacks? They’re drawn masks only (as far as I know), but maybe something to look into…

1 Like

You can actually get Enfuse to dump the masks it uses (I mention it in this old blog post) if you ask it to:

enfuse --save-masks=%f-softmask.png *.jpg
1 Like

If you shoot raw, can’t you just get two versions of one single image with different exposure?

1 Like

Nice!! :grin:
Good idea using the two foregrounds…I’ll have to play with that idea. Thanks.

I actually tried a masking version of the image I show in above mentioned video, and failed miserably. Problem is that the transition in that image isn’t sharp so you have very carefully decide what to take from which exposure and then blend it smoothly, which is not easy.

1 Like

By shooting raw you can adjust the exposure afterwards to some extend. But this is limited by the dynamic range of the sensor. Depending on the dynamic range of the scene and the sensor of your camera, you could get away with a single raw image, that is exposed such that the highlights are captured “correctly”. The histogram would indicate a fairly underexposed image. The shadows can then be adjusted in post.

Modern cameras have 12-14 bits sensors and aven accounting for sensor noise this gives them a 10-11EV dynamic range, while JPEGs are 8-bit, so there is a 2-3 bit/EV margin. And yes, you can always under-expose a bit.

Cameras are linear but JPEGs are gamma encoded, so they are capable of handling more than 8EV

Yes, absolutely. In fact this is something I’ve done in the past when the masking got too complicated for fiddling with in the raw processor.

About the blending between the two exposures, just did an experiment that turned out fairly well(*):

  • put the light version on top
  • add a layer mask to it; initialize to grayscale copy of layer, inverted
  • play with curves on the mask

(*) the picture used is so abysmally without artistic merit that I won’t show the result here :slight_smile:

Yes you can use Hugin and the masks are hand drawn only. :slight_smile:

1 Like

My humble opinion on this:
If you can do the above mentioned, then you can just process the one raw file you have to get to the desired result. You don’t generate new information by creating two processed images from the same raw file.

With some advanced raw processors, yes, but the more basic ones will just apply a uniform process on the whole image. But point taken.

This approach is new to me, and I will have to try it. As others have suggested, one might achieve similar results using a RAW capture exposed with this purpose in mind (yes, one would have to underexpose the foreground just enough to keep sky highlights from blowing). Darktable’s parametric masks might make simple work of this task.
Thanks for the tutorial. I’ll have to play around with this a bit.
Caruso

1 Like