An Excellent Free and Open Source focus-stacking solution

I recently upgraded my camera to a Nikon Z8 (review to follow at some point), specifically because it has a focus-shift mode where it will take a sequence of photos at different focus points to later combine.

One thing I didn’t realise was just how difficult merging those images into a single, fully focused image is. I’d assumed it would be something I could tear through with a batch process in Photoshop or similar. But both Photoshop and Affinity Photo are terrible for it. The process is slow, barely automatable, and clunky as all hell.

I was directed to Helicon Focus, which is very fast, and very easy to use. It’s not unreasonably priced either, at $30 a month, or $115 for a lifetime license, both for the Lite version.

However, from the demo (and from a colleague who has a licence), my outputs weren’t at the original resolution (nowhere near, not just missing a bit from a crop), and more importantly, it was doing something to the EXIF data that meant the outputs wouldn’t run in reality capture at all (which is weird given that JPGs without any EXIF data can work fine).

Given that experience, I kept searching, and came across focus-stack on github, by Petteri Aimonen.

It’s command line only, but it’s simple enough – the program, the inputs, and the output, e.g.:

focus-stack.exe \*.JPG --output myoutput.png

Obviously you need to have your photos organised properly, and be able to call the executable from wherever your terminal currently is, but it doesn’t get much simpler than that.

As an added bonus, it’s dead easy to make a batch script to process a bunch of folders. The Z8 automatically puts each set of focus-shift images in it’s own folder, e.g.:

In each folder are 25 images of varying focus position. Each image is 8256 x 5504 pixels, and is about 10mb in size. Here’s some samples from an ammonite about 2 cm across. Images were captured with the Nikon Z8 with MC105 f2.8 VR lens, at f4.

So I wrote the following powershell script that ran through all of them (these are in a folder called ‘photos’, and above this folder is a folder called ‘focus-stack’ that contains the focus-stack program and libraries):

#a powershell script
#we are in a directory containing folders from 133NCZ_8 to 147NCZ_8
#for each folder I want to run a certain command.
#for 133 it looks like: ..\focus-stack\focus-stack.exe .\133NCZ_8\*.NEF --output=133.png
#I want to run this command for each folder from 133 to 147
for ($i=133; $i -le 147; $i++)
{
    ..\focus-stack\focus-stack.exe .\$($i)NCZ_8\*.JPG --output=$i.png --verbose
}

It takes about 50 seconds to process all photos into a single file (I need to see if it’s properly using my GPU). The output resolution is identical to the input photos. If exporting to a PNG it’s 60mb in size, a jpg is 9.47 (so about the same as the inputs).

Here’s the result of focus-stack:

Output from focus-stack.exe

Now, in fairness to the focus-stacking software, my gap between focus positions is a bit large so it’s not perfect. But it’s still pretty bloody good.

For comparison, Helicon focus (the demo version) took less than 9 seconds! It produced a similarly excellent image:

Helicon focus output

This is Helicon Focus in action (in real time):

However, this image is only 1620×1080 in resolution – a significant downsizing. Not clear if this is limited to the demo version, the lite version, or all versions of the software.

So yeah, Helicon focus is amazing, but there’s some small niggles, and it does cost $100 or more for a lifetime license.

Focus-stack is free, and while it’s a bit slower, it’s easy to batch process while you go get a coffee, and in my opinion the outputs are just as good.

I’ll have a post to follow soon where I compare some photogrammetry models with focus stacking.

One thought on “An Excellent Free and Open Source focus-stacking solution

Add yours

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Built with WordPress.com.

Up ↑