Image stacking for improved dynamic range with 100% open source software

Started Dec 28, 2017 | Discussions thread
ForumParentFirstPrevious
Flat view
Entropy512 Senior Member • Posts: 4,595
Image stacking for improved dynamic range with 100% open source software
6

This is something I have been playing with for a while, and after some trials and errors have been getting good results.  This was done on a machine running Ubuntu 17.10, but any machine with recent enough versions of darktable, ImageMagick, and hugin will do the trick - I BELIEVE all three are now theoretically available for Windows.  This is one case where Mac and Linux users will be better off. 

Now, this isn't exactly new, but it merits a fresh look now that Sony cameras are ditching the PMCAs such as Smooth Reflections. The reality is - it has always been and still is possible to obtain better results with no apps. That benefits FF users more than APS-C - but I'm still on an A6500 and even for people who still have the PMCA there are advantages (for example I'm fairly certain based on other users comments that the SR app does not do image alignment, making it require a tripod.)

This is also known in some use cases as multiframe NR - but has more flexibility (much greater number of stack images, more flexibility to make changes to the stack post-capture).

This is based on the work of Jim Kasson at http://blog.kasson.com/the-last-word/an-mf-camera-in-your-jacket-pocket/ and by Dierk Topp at https://www.sonyalpharumors.com/sony-a7rii-shooting-high-iso-get-clean-images-almost-no-noise-dierk-topp/, along with assistance from commenter "Jonathan F.V." on Dierk's SAR article.

First - Set up your camera in continuous drive mode, and set the shutter speed high enough to be sure you won't get blur in each frame.  Choose your desired aperture, then adjust ISO until your highlights are almost clipping (potentially you might still be clipping some highlights if the dynamic range of your image is really extreme).  Don't worry if the ISO is climbing pretty high here - the noise of a single image is not of particular concern.

Second:  Focus on your scene and then let er' rip.  Just keep up the burst until the buffer gets full (80+ images).  Depending on the scene you might not need as many images, but for some scenes you're going to want lots of data.

Individual images are going to look pretty horrible, such as this - 1/50 sec at ISO800, f/6.3 - note that I scaled it down to 3000x4500 during raw conversion as I really didn't need full resolution, but that is up to you.  Downscaling will reduce noise further if you're posting to a medium that doesn't need the resolution.

Of note:  The processing workflow kills EXIF, so most if not all of my images will be missing it.  I'm going to try to describe the conditions for each of them as accurately as possible to compensate.

Pretty severely underexposed...  If you WERE to try to bump up the exposure you get this:

The noise is horrible.  I've had stacks where it looks even worse.

Third:  Transfer the images from your burst to your PC.  Open up Darktable and import the folder with your ARWs.  Make sure to click "ignore JPEG" if you shot JPEG+RAW.

Double click on the first image to bring up the darkroom.  Adjust white balance as necessary - don't worry about exposure.  That will come later/be handled by HDR.

Go back to the lighttable, select the image you tweaked, and hit Control-C to copy the edit history.  Now select the whole folder and hit Control-V to paste the settings to all images.

Now open up the "Export Selected" tool in the lighttable pane, and I strongly suggest putting your TIFs in a subfolder of your current folder.  Change the output format to TIF and change the depth to 16 bits.  32-bit float may be beneficial, but it's iffy - ImageMagick may be limited to a 16-bit pipeline.

Then export all your images.  Once this is done, you can close darktable.

You'll be on the command line from now on - for some of you this may be difficult, but for many of us Linux veterans it's where we thrive.    Others have mentioned alternate workflows that are more GUI-y but aren't necessarily 100% free, but at least this should serve as inspiration for alternative ways of doing this task.

Fourth:  Create a subdirectory of the location you exported the TIFs to - yes this may be a subdirectory of a subdirectory.  Change directory to that.  Then run (requires hugin to be installed, if you get a command not found error, install it.  Trust me, you want it around if you ever decide to try panorama stitching!):

align_image_stack ../*.tif -C -v -a aligned

This will take quite some time - the -v option makes it spit out its progress.  -C causes it to crop all images to the "common" area covered by all images after alignment.  If the end result is too small/too aggressively cropped, you need to hold the camera more steadily.

When it finishes, you will have a bunch of images named alignedNNN.tif - these are 16-bit sRGB TIFFs that are now aligned so that they are all covering the exact same field of view - or at least they should be!

Fifth:

Run the following command (requires ImageMagick):

convert aligned*.tif -evaluate-sequence mean merged.tif

This will take a long time too, and ImageMagick MAY give out-of-cache errors.  If that's the case, you'll need to bump up the memory, map, and especially "disk" entries in /etc/ImageMagick-6/policy.xml - unfortunately Ubuntu puts in some really restrictive defaults.  This process may require more than 10GB of scratch disk space.  Alternatively, you can merge 10 images at a time, and then merge the intermediary images with the same command - but this requires a lot more manual intervention.

You will eventually have a 16-bit TIFF with very low noise - For example, in my case, 124 images at 1/50 sec and ISO800 roughly equates to 2.48 seconds exposure at ISO 6.45 - yes, that's right, 6.45.

Sixth:

Create a set of images at various pushed exposures.  ImageMagick's level command is a bit counterintuitive, but it increases exposure by defining the white clip level in percentage.  I'm still not sure if that's in the linear space or in sRGB gamma-encoded values - it works well enough for now even though there are parts of this workflow that probably would work better if done in linear space instead of sRGB.  I need to give a fully linear workflow until the final result another try at some point.

convert merged.tif -level 0x8% 8.tif

Do the same for 16, 32, and 64 - you may if you wish have more intermediate steps, but enfuse fed with 16-bit TIFF input seems to do fine with 8,16,32,64, and "normal".  You may want to adjust the brightest image to be not TOO bright - a value of 8 is an extremely aggressive push.

Seventh (requires enblend, which is automatically pulled in by hugin):

enfuse 8.tif 16.tif 32.tif 64.tif merged.tif -o fused.jpg

End result, in my case:

Note that you can also use this technique in much brighter light to simulate a very low ISO - allowing you to get away with not needing an ND filter to synthesize very long exposures.  In this case, my goal was handheld in low light.

 Entropy512's gear list:Entropy512's gear list
Sony a6000 Pentax K-5 Pentax K-01 Sony a6300 Canon EF 85mm f/1.8 USM +5 more
Sony a6500
If you believe there are incorrect tags, please send us this post using our feedback form.
ForumParentFirstPrevious
Flat view
ForumParentFirstPrevious
Keyboard shortcuts:
FForum PPrevious NNext WNext unread UUpvote SSubscribe RReply QQuote BBookmark MMy threads
Color scheme? Blue / Yellow