compilerbitch: That's me, that is! (Default)
[personal profile] compilerbitch

Synthetic HDR

From SarahWiki

In recent times, it has been very difficult to miss the craze for HDR (High Dynamic Range) photography. Put simply, the technique involves creating a series of photographs of the same scene, with varying exposure in each case. The images are then recombined into a single high dynamic range image, often at 32-bit depth, that retains highlight and shadow detail that no individual image from the series can contain. These HDR images are then tone mapped back to an 8- or 16-bit image that is within the capabilities of displays and printers (and, for that matter, the human eye).

Image:Lj-Weightstrip.jpg

7 images taken 1 f stop apart

For the above example, I shot 7 separate images, all at f/16, at shutter speeds one stop apart across the whole range, with a 100mm macro lens and bellows on a Bronica ETRS with a Megavision E4 Monochrome digital back (which has a 12-bit, 16 megapixel, 4096x4096 CCD image sensor). No single image manages to capture both the texture of the black cloth (a black towel) and the detail within the highlights on the brass weights. When I attempted to merge them to a single HDR image with Photoshop, I found this to be impossible because my machine didn't have enough memory. Since my PC is a dual-core Athlon with 4GB of RAM, there was no way I was going to be able to merge these images at full resolution, so I made 800x800 versions of all of them instead for the purposes of this article. The image above is the exact output of the HDR merge operation on Photoshop -- it's clear that it has done a good job of retaining detail across the range of exposures.

Image:Lj-Real-hdr-32bit.jpg

32-bit HDR image (converted to 8-bit without contrast alteration)

But let's imagine that the standard approach to HDR isn't possible -- maybe there was movement in the scene, or it was only decided after the shoot that HDR was going to be necessary in order to pull out enough shadow detail from an existing image.

Image:Lj-Synthetic-hdr-version.jpg

Synthetic HDR image

In this article, I describe a technique that I'm going to call Synthetic HDR -- that is, a means of extracting an HDR image from a single original shot. What I'm about to describe isn't snake oil -- it's not just the same as creating several versions of the same image (e.g. in Adobe Camera Raw) then HDR merging them -- this technique really can extract up to an extra 8 bits or so of dynamic range from a single image. As you can see from the above examples, the results aren't identical, but I think it's clear that they are sufficiently close that it does demonstrate that the technique works. There will be some science, and some maths, but there will also be a step-by-step 'how-to' for reproducing these results armed only with Photoshop CS2. At some point I'll probably write a Photoshop plugin that will streamline the process, but for now, if you follow the steps exactly, you should get equivalent results.


Theory

Let us assume that we are starting (as in the above example) with a single source image that has a 12-bit dynamic range:

Image:Lj-Base-image.jpg

Base image

I chose one of the darker originals because it demonstrates just how much shadow detail can be recovered with this approach -- initially, it doesn't appear that there is even any information in the shadows at all.

Binning

Image:Lj-2x2binning.png

A technique for increasing the sensitivity of image sensors, at the expense of resolution, has been known for a long time. Binning typically involves subdividing an image sensor into (usually) square blocks of pixels, then summing the intensity across the block. In some cases, this is carried out within the image sensor chip with analogue electronics. Alternatively, binning can be applied digitally later.

Typically, with 2x2 binning, as shown in the above diagram, you get a reduction of image resolution of a factor of 2 in each axis, or a 4 times reduction overall. However, quite literally, not all of the information is lost. If, for example, the original pixels were represented as 8 bits (i.e. with 256 possible values), the resulting binned pixel has 1024 potential values -- this equates to 10 bits of dynamic range. Doing, say, 5x5 binning on the same image data would give a 25 times multiple of the number of possible pixel values, resulting in (almost) 8 extra bits of dynamic range. At the expense of resolution, then, it is clear that it is possible to increase the dynamic range of an image more or less arbitrarily.

Of course, this isn't usually how binning tends to be used in practice. Generally, it tends to be used to increase the light sensitivity of the sensor, so typically the same bit depth as the original image is retained, with any value greater than the limit being hard-clipped to the upper end of the range. Used in this way, 2x2 binning gives a 4 times increase in light sensitivity, equivalent to 2 f-stops.

HDR revisited

OK, we now know that we can have all the dynamic range we could reasonably want, if we are prepared to live with greatly reduced image resolution. But can we do better than this?

Returning to the 'traditional' HDR technique that involves making a series of photographs at different exposures then recombining the images later, such that the 'good' (mid-range) tones from each component image are used preferentially to assemble the final image. Here comes the big idea: perhaps we could simulate different exposures with binning, then use established HDR techniques to recombine them into a final image, such that the inevitable loss of resolution is just confined to shadow areas?

Amazingly enough, it seems to work. Here's how.

In my experiment, I three extra images from the original base image. Rather than binning as-such, I used a related technique, convolution, which I used to sum groups of pixels similarly to binning, except that the n by n matrix is moved along one pixel at a time, rather than n pixels at a time as it is with binning. This means that the resulting image is the same resolution as the source image, though blurred slightly (this is very close to what a blur filter does, but there are slight differences).

Taking the source image, I then filtered it with a Photoshop 'Custom' filter (you can find it in the menus as 'Filters | Other | Custom...') set up as follows:

Image:Lj-2x2customfilter.jpg

Note (important!) that Scale is set to 1 -- normally this is used to rescale any increases or reductions in image brightness, but I deliberately want it set to 1 because we specifically don't want any scaling. Here, I've set up a 3x3 grid of 1 values -- this has the effect of doing 3x3 binning, with a resulting 9 times increase in dynamic range (a bit over 3 bits). The resulting image is as follows:

Image:Lj-3x3binning.jpg

Image after a 3x3 convolution ('binning') transform

It's interesting to compare this with the original -- the roughly 3 stops of extra effective exposure has made the cloth visible and blown out the highlights.

Next, I did a 5x5 binning convolution based on the original image, again with a Photoshop Custom filter:

Image:Lj-5by5customfilter.jpg

which gave results that look like this:

Image:Lj-5x5binning.jpg

Image after a 5x5 convolution ('binning') transform

This version of the image now very clearly shows detail in the cloth, representing a 25 times increase in exposure, a bit more than 4 and a half stops.

At this point, I decided to take this to something of an extreme by now applying a further 3x3 convolution:

Image:Lj-5x5binningThen3x3binning.jpg

Image after a 5x5 and a 3x3 convolution ('binning') transform

This is maybe going a bit far, but it does serve to show just how much can be dragged out of the fine detail. The noise looks quite pleasingly like film grain, though (obviously) this image is so blown out that it's useless for anything other than HDR.

The next step was to do an HDR merge on the images, which resulted in (after mapping back to 8 bits) the following image:

Image:Lj-Synthetic-hdr-version.jpg

Synthetic HDR image

The detail on the metal looks a bit flat and lifeless in comparison with the 'real' HDR image, but this is mostly just differences in brightness and contrast and nothing that couldn't be fixed with some dodging and burning. What is very clear, though, is that where the original had almost no visible shadow detail, the synthetic HDR image is almost identical to the 'real' HDR image.

Comparison with Levels

The obvious question that people will inevitably ask is, how does synthetic HDR compare with simply creating a series of Levels layers and then compositing them? By way of an example, here's what a 100% crop of the bottom right hand corner of the original image looks like, brightened to fill the full 0-255 grey scale range:

Image:Lj-Bottomrightoriginalautolevels.jpg

100% crop, bottom right corner of original image, auto-Levels

Not pretty -- really evil noise and gross posterisation. A 100% crop of the same area of the synthetic HDR image is as follows:

Image:Lj-Bottomrightsynhdrautolevels.jpg

100% crop, bottom right corner of synthetic HDR image, auto-Levels

Definitely much nicer. No visible posterisation, and what noise there is looks like film grain. Perhaps surprisingly, there is little to choose between the images in terms of perceived sharpness -- I suspect that this is partly because our own human visual system probably does something not unlike synthetic HDR in making sense of the very noisy, pixellated original image. There are some slight square-edged artifacts, most likely due to the square edges of the convolution kernels that I used, but this could be avoided by using circular kernels instead of rectangular ones, but they would be a little more difficult to explain so that will probably have to wait for the plugin when I write it.

References

  • Paul E. Debevec and Jitendra Malik. Recovering High Dynamic Range Radiance Maps from Photographs, Proceedings of SIGGRAPH 97, Computer Graphics Proceedings, Annual Conference Series, pp. 369-378 (August 1997, Los Angeles, California). Addison Wesley. Edited by Turner Whitted. ISBN 0-89791-896-7

(no subject)

Date: 2007-03-29 11:49 pm (UTC)
From: [identity profile] cuthalion.livejournal.com
That's pretty clever! I don't like your term for it though - to me, "synthetic" implies synthesis (from multiple source images).

(no subject)

Date: 2007-03-29 11:55 pm (UTC)
From: [identity profile] compilerbitch.livejournal.com
I'm using it in the sense of Synthetic Aperture Radar, i.e. you're simulating an aperture when you haven't really got one. In my case, I'm simulating HDR when I don't really have the source images for it. If you see what I mean...

(no subject)

Date: 2007-03-30 12:01 am (UTC)
From: [identity profile] cuthalion.livejournal.com
But SAR works by combining a whole bunch of pulses and measurements to create a single image. Which is why it's synthetic.

(no subject)

Date: 2007-03-30 11:38 pm (UTC)
From: [identity profile] compilerbitch.livejournal.com
... which is what I'm doing with convolution. So there. Ner! ;-)

(no subject)

Date: 2007-03-30 12:11 am (UTC)
From: [identity profile] x-mass.livejournal.com
could you use this plug in in after affects?
i.e. could you use it on motion video?

(no subject)

Date: 2007-03-30 12:15 am (UTC)
From: [identity profile] compilerbitch.livejournal.com
I don't see any reason why not. The transforms are all stable and deterministic so it should work fine with video.

(no subject)

Date: 2007-03-30 02:05 am (UTC)
From: [identity profile] celesteh.livejournal.com
Wow, I'd been wondering for a while what the non-audio uses of convolution were. I've heard of it being used for other things, but hadn't done any reading about it. I use convolution all the time, but for audio, mostly doing reverb or filtering. I just wrote something about how do "subliminal messages" with convolution, but it actually is more like a really odd low pass filter: http://celesteh.blogspot.com/2007/03/subliminals-timbre-and-convolution.html

(no subject)

Date: 2007-03-30 02:43 am (UTC)
From: [identity profile] compilerbitch.livejournal.com
Convolution is used all over signal processing -- you get 1D convolution used for things like audio and radar. 2D convolution is used a lot for image processing. You even get 3D convolution for volumetric data in some scientific applications.

It's worth knowing that there is a duality between certain operations in the frequency domain and equivalent operations in the time domain. If you, for example, construct an narrow band-pass analogue audio filter, then put a pulse through it (a unit impulse in the textbooks), what comes out looks like what the end of a ruler does when you twang it on the edge of a desk. If you then take that twang, extrapolated against time, and convolve a piece of audio against it, you get the same frequency response, Q and everything, that the analogue filter would have given you. In recent times, people have been doing fancy things by exploiting the convolution duality in the other direction -- convolving audio (or anything) in the standard way is computationally quite expensive, because it takes a number of additions an multiplications equivalent to the size of the convolution kernel for each sample in the audio (say). However, if you transform the audio into the frequency domain (e.g. with an FFT), you can then apply the convolution in the frequency domain (which is typically cheaper), then do an inverse FFT to recover actual audio again. This trick works when the convolution kernel gets big enough that the FFT/inverse FFT overhead is less than the cost of doing an ordinary finite impulse response (FIR) convolution.

(no subject)

Date: 2007-03-30 12:55 pm (UTC)
From: [identity profile] celesteh.livejournal.com
Indeed. The phase information keeps the timing correct too. SoundHack is a very nice free mac application which does FFT-based convolution. Also, FFTW is really really fast, but you have to do your own coding around it.

(no subject)

Date: 2007-03-30 02:25 am (UTC)
From: [identity profile] midendian.livejournal.com
This is neat.

So I tried it, and I can't get any image at all with a scale set to 1. Increasing the scale gets a picture, but obviously not the method you intended. What am I doing wrong? I've never used the custom filter thing before, so maybe I'm totally missing something.

(no subject)

Date: 2007-03-30 02:35 am (UTC)
From: [identity profile] compilerbitch.livejournal.com
You probably need to do a 'Levels' on the original image first to get the shadows down close to zero -- without that, you'll probably just end up with a white frame by the time their values are multiplied. In the plugin, this will hopefully be automatic, but if you do it by hand it'll take a bit of fiddling unfortunately.

(no subject)

Date: 2007-03-30 06:25 am (UTC)
From: [identity profile] andrewwyld.livejournal.com
That's awesome!  Just a thought (and this might be more work than it's worth) but couldn't you create the same result with an irregular pixel bin?  I don't know how easy it would be to do but it would create the illusion of fast film grain even more perfectly.  In fact, if the bin sizes varied slightly you'd have the same slight irregularities in sensitivity you get with real film grain as well.  You're talking a bit more custom coding but it could look pretty awesome.

That said, I love this technique.  It's obvious when you think about it, but I never did.

(no subject)

Date: 2007-03-30 06:46 am (UTC)
From: [identity profile] compilerbitch.livejournal.com
I've been fiddling around a bit with kernels shaped like film grain -- it seems to work pretty well actually. It's a bit like having an emulsion that's thick enough to have layers of grain overlapping slightly (which is how it is in the real thing). The results seem pretty good. The plugin implementation will work this way, partly because I want to make the EV increases exact integers because it drastically simplifies the maths, so I need to pare down the kernels slightly.

(no subject)

Date: 2007-03-30 06:49 am (UTC)
From: [identity profile] compilerbitch.livejournal.com
It's obvious when you think about it, but I never did.

I *like* those ideas the best! I basically rushed this write up a bit because I wanted to get the idea out there quickly. I posted on Luminous Landscape's forums too, and got flamed for my trouble, but that's reasonably standard there.

(no subject)

Date: 2007-03-30 06:55 am (UTC)
From: [identity profile] andrewwyld.livejournal.com
Me too--those are the ideas that it will one day be hard to imagine life could ever have been without.

By the way, is there a way to use conventional HDR techniques with Ilford XP2 film?  I think it's supposed to have a huge dynamic range but you need multigrade papers to get at it, basically.  I would think multiple electronic exposures of a single XP2 negative would give good results.

(no subject)

Date: 2007-03-30 07:47 am (UTC)
From: [identity profile] compilerbitch.livejournal.com
You could probably do it with a film scanner if you can alter the scanner's exposure within a few stops range. It won't do much if the scanner just 'fakes' exposure digitally though, for obvious reasons.

Some people claim good results from processing images from the same RAW file several times with different exposure settings -- I can't see that this would give you any advantage over saving the image out at maximum bit depth once, then just tone mapping it as-is.

(no subject)

Date: 2007-03-30 08:43 am (UTC)
From: [identity profile] keithlard.livejournal.com
That is wizzo pet thanks! I do not know about such as all the tecknical details, but it is reely intresting.

(no subject)

Date: 2007-03-30 08:08 pm (UTC)
From: [identity profile] compilerbitch.livejournal.com
Why thank you. :-)

(no subject)

Date: 2007-03-30 12:00 pm (UTC)
liv: cartoon of me with long plait, teapot and purple outfit (Default)
From: [personal profile] liv
Thank you, this is fascinating. The more so because we use binning in digital imaging of fluorescence microscopy to increase sensitivity at the expense of resolution, and I had never understood how it works. I wonder if I could adapt your technique to get better quality images when I'm working at the limits of the CCD. (I'm fairly certain that capture, not the microscope optics, is the limiting factor for looking at very few molecules with a less than optimal antibody.)

Also we use "deconvolution" to determine accurately whether two proteins are in the same place in the 3D space of the cell. I assume this is the reverse of the convolution that you have described, and another thing I was using without understanding the theory. Cool.

(no subject)

Date: 2007-03-30 07:47 pm (UTC)
From: [identity profile] compilerbitch.livejournal.com
Yes, this technique should work on the kind of images that you work with. Essentially it's like being able to use binning to different levels depending on how light or dark different parts of the image happen to be, so bright features stay sharp whilst darker features are at least still visible, if slightly blurred. Used on top of conventional binning, it might well give you a few stops worth of sensitivity increase, so I'd say give it a try. I'll probably have the plugin working relatively quickly (famous last words), which should make it as easy as using the standard Photoshop filters.

(no subject)

Date: 2007-03-30 08:06 pm (UTC)
From: [identity profile] compilerbitch.livejournal.com
Deconvolution is exactly what you suspect it to be -- an inverse transformation that gives you increased sharpness by undoing a (usually conceptual rather than actual) convolution.

Weirdly enough, deconvolution is usually actually done with convolution, but with different coefficients in the matrix. It's an extremely powerful technique.

(no subject)

Date: 2007-03-30 02:39 pm (UTC)
From: [identity profile] captain-aj.livejournal.com
Woah, awesome. *BOOKMARKED*
Poor dynamic range has been p-ing me off for years, I'd just never considered this. Now I need a really good steady tripod :-)

(no subject)

Date: 2007-03-30 11:37 pm (UTC)
From: [identity profile] compilerbitch.livejournal.com
What you probably really need is a cable release. :-) They cover a multitude of tripod-related sins! I hardly ever shoot without one with the medium format gear, even when I'm using the motor drive.

(no subject)

Date: 2007-03-30 06:41 pm (UTC)
From: [identity profile] davefish.livejournal.com
I do like the articles you write :)
Anyhow, getting on with it, I've piddled around with similar things before, trying to sort of some of my gig images, essentially doing two extractions from the RAW to JEPG, one to get a performer looking sensible, adn another for the surroundings, then combining them with layer masks. Unfortunately my PS-fu is that of a grasshopper, rather than that of a ninja master, so they never quite worked as I would have liked, as I could always see some edges to the effect.

You have bumped into my fave thing to grumble about in the notation PS gives to images, namely that of high dynamic range. Its fine talking about 32-bit dynamic range when you are talkingabout the software capabilities, but as soon as you have a real image, that starts to fall over. I wouldn't say that your 2x2 binning gives you a 2-bit increase in dynamic range, just a 1 bit increase, since at the low end you'll be likely doubling your noise floor. This complaint does hold for the rest of the world of photography though, as I have to admit that even the idea of going from 12 to 14, and on to 16 bit capture is something that I am not convinced of the validity of. Shot noise is a powerful master, and I fear him greatly.

That said, I will probably enjoy playing with any plug-in you write :)

(no subject)

Date: 2007-03-30 07:40 pm (UTC)
From: [identity profile] compilerbitch.livejournal.com
Actually, you *want* a bit of noise to make this technique work, really. Having a bit of dithering going on at the bottom bit or so doesn't really do any harm, and also helps avoid weirdness due to quantisation effects like Mach banding and so on.

I'll have to do some sums to figure out how much noise you end up with. Ultimately I doubt it really matters much because the results I got even with the Photoshop technique looked a lot better than the raw image, but at least I have *some* maths to back up what I'm doing. :-)

(no subject)

Date: 2007-03-30 10:55 pm (UTC)
From: [identity profile] davefish.livejournal.com
I'd say that there would be very little chance of not having noise! Certainly on bigger scientific detectors it almost always ends up being shot noise limited, unless you have really low signals. And shot noise is much much nicer than quantisation noise, both from a perceptive point of view, and also from the point of view of doing something about it.

As you say, I doubt that it matters that much since you are getting quite a bit further than with a simple capture alone (At least from the point of view of the detail recovered in PS.)

(no subject)

Date: 2007-03-30 11:10 pm (UTC)
From: [identity profile] compilerbitch.livejournal.com
You'd only get an absence of noise if you were clipping the black level or running without enough bits of resolution on the ADC. For my purposes, it's certainly better to have it (at least to some extent) there! But yes, posterisation looks horrible usually, so swapping that for noise is always favourite. More than once I've deliberately added noise to a sky to break up Mach banding -- I tend to get problems with converting particularly Better Light images shot at low ISO ratings back to 8 bits, because there just isn't enough noise. Oh well, you can't have everything, I suppose! :-)

(no subject)

Date: 2007-03-30 11:20 pm (UTC)
From: [identity profile] davefish.livejournal.com
I've been surprised at hwo well some images I've taken have come out given the conditions, when you run them through the smallest amount of 'noise reduction'

Using the Canon RAW conversion software, I got the shots below at a gig at Slimelight, where I was mainly shooting at ISO 1600, and underexposing one stop.

http://www.davefishphotography.co.uk/Music/TdVSlimelight/DUST/index.html

(no subject)

Date: 2007-03-30 11:32 pm (UTC)
From: [identity profile] compilerbitch.livejournal.com
That's pretty neat -- they look really clean, and you've obviously had plenty of sensitivity to pick up the caustics from the lights.

Profile

compilerbitch: That's me, that is! (Default)
compilerbitch

January 2016

S M T W T F S
     12
3 45 6789
10111213 141516
17181920212223
24 252627282930
31      
Page generated Mar. 23rd, 2026 08:34 am

Style Credit

Expand Cut Tags

No cut tags