Jump to content
  • entries
  • comments
  • views

Improving Photos with "Focus Stacking"

To take good photos of model railways it's really important to control the depth of field or focal depth of the image. This is best demonstrated by @KNP's wonderful photographs of his masterpiece, Little Muddle.

This blog entry describes my first experiments in improving depth of field in my photos.


Why Depth of Field matters

Definition: The Depth of field is the distance between the nearest and furthest objects that are acceptably in focus.


I'm not a photography expert and I don't claim to understand all the technicalities of depth of field but in a nutshell, the closer the camera is to the subject, the smaller the depth of field. Or to put it another way, when the camera is close to the scene only details at a very specific distance from the camera will be in focus and the rest of the image will be blurry. (This is to do with the angles of light rays entering the camera.)


Real world photos have a much deeper range of good focus because of the greater distance between the camera and the subject. (Technically, because of the smaller angles at which the light rays enter the camera.)


So small depth of field is a problem when photographing models for two reasons:

  1. When you focus on a particular item of interest it means that many other details are out of focus. E.g. you focus on the smokebox of a loco and then the cab, which is only a few centimetres further back, is blurred.
  2. The lack of focus is not just annoying in it's own right but it's a dead give-away that you photographed a model, no matter how realistic your detailing was!

Focus Stacking

So we want a way to increase the depth of field when photographing our models and this is where technology comes to the rescue in the form of "Focus stacking" or "Focus merging".


A focus stacking algorithm analyses several photos taken at different focal lengths and mixes the best focused parts, the sharpest parts, to create one good image.


How to do focus stacking

To apply focus stacking you need to:

  1. Capture your images digitally. Many compact digital cameras and Smartphones have very good lenses and high resolution sensors and are perfect for this task.
  2. Capture a number of images without the camera moving. To ensure that the camera doesn't move while capturing the images you need you ideally need some sort of tripod. A mini tripod with a swivel mount and flexible legs is ideal.
  3. Capture images at a range of focal distances. You could attempt to refocus manually between each shot but it's much easier and more reliable to let the software on the camera do this for you. Some cameras have that feature built-in and there are apps for Smartphones to do it.
  4. Collect the images together and process them in a suitable software package. Many high-end photo processing software packages have the ability to perform focus stacking and there are some free apps and utilities.


My first experiment

I used my Android SmartPhone, a OnePlus 3, mounted in a swivel head on a small tripod.



To capture the images automatically I installed a free app called, OpenCamera, which gives much more control than the standard Android Camera app. Here it is in operation:


The two large sliders on screen set the front and back focus points for the stack. The smaller third slider is the zoom factor. The software is set to take 16 images in this example but it can take up to 200!


[Edit: OpenCamera requires a phone and a version of Android that allows apps to control the camera focus.]


To process the images I first tried an open source desktop application called CombineZP but I found it to be difficult to use and not very reliable. In the end I settled on Affinity Photo, a highly accomplished and very affordable desktop photo editing package which has a good focus stacking feature. (This was a hard thing for me to do because the Affinity software is "the competition" in my professional life!)


Here are two of the raw images, numbers 2 and 12 from the stack of 16:


You can see that image number 2 is focused near the smokebox door of the loco but the background is out of focus. And image number 12 shows the background train in focus but the loco is blurred.


Then the full stack of 16 photos was given to Affinity Photo and it produced this result (after cropping):



You can see that the process works and it was quite easy once I had gathered together all the necessary tools. I will do some more experiments and try some creative ideas.


  • Like 3
  • Informative/Useful 9


Recommended Comments

Thanks for link to the app :) 


I generally use a custom script on my Canon that shoots from the current focus up to the hyperfocal length of the lens then stack in Photoshop CS6 but it will be handy to use the phone if I've not got my full kit with me :)

  • Informative/Useful 2

Share this comment

Link to comment

Ah codfanglers, I don't get the Camera2 api come up on my Sony phone. Back to the Canon ;)

Share this comment

Link to comment

Very useful post, thanks Harlequin. I'll see if that app works for me, sounds like just the thing I've been looking for.


I've found that depth of field isn't always desirable - if you want to really foreground something for example - but in general it does make a huge positive difference.

  • Agree 1
  • Thanks 1

Share this comment

Link to comment

Posted (edited)

Thank you for a most helpful blog post.


I have a studio camera with movements. It's one of those things I wanted for many years, and then realised its limitations as soon as I started with it - mainly its bulk and its appetite for roll film. Anyway, I did apply it to model trains some years ago and here is an example of controlling DoF with movements. The lens is turned somewhat to the left, and also titled vertically to keep the vertical things upright. This photo is scanned from a negative but no subsequent editing. Can we can produce this sort of effect with focus stacking? That is, setting the area of focus diagonally across the depth of the subject. If so please do post up the details.


Edited by 47137

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.