Skip to Navigation Skip to Content Skip to Search Skip to Site Map Menu

Focus stacking images

This article has been specifically written for using the macro-photography setup in the Graphics Lab in the geology department and Adobe Photoshop CS5. Concepts are applicable to other equipment and versions of Photoshop.


I have made a new post with instructions using Zerene stacker to stack the images rather than photoshop because it is faster, easier and produces better results in all cases that I have seen. For example Zerene Stacker took 72s to stack 11 images and photoshop took 125s, the difference in stacking speed is even more pronounced when more images are used.

Background information

What is focus stacking?

Focus stacking is the process of stacking (combining) multiple images with different levels in focus into a single image that is “in focus”.

What controls depth of field?

There are several factors that affect Depth of Field (DOF). Most compact cameras have a far greater DOF than DSLRs. For DSLRs the primary factors are lens focal length, subject distance and Aperture size (f number).

  • Focal length: The Macro photography setup in the Graphics Lab is a 50mm prime lens so we can ignore the effects of changing focal length.
  • Camera to subject distance: the closer you are to a subject the narrower the depth of field.
  • Aperture size: The smaller the aperture size (greater f number) the greater the depth of field.

For more information look at the Wikipedia article on Depth of Field

When do you need to focus stack?

You may need to focus stack when you are trying to take a photo of something with a lot of relief, i.e. distance between the front of the object and the back when viewed from the camera. The most typical situation is photographing a small (cm-sized) specimen (e.g. a small brachiopod) that has depth on the order of its width/height when viewed in the orientation it needs to be photographed in (e.g. it’s roundish). Samples that are quite flat are usually ok.

Before attempting to focus stack

It’s a good idea to see if you can get enough depth of field by adjusting the f-number (aperture size) up to something like 20. Please note that image quality (e.g sharpness) does degrade with higher f numbers.

Another approach is to simply move the camera further away and then digitally crop the picture. This may be suitable if you don’t need a really high resolution image.

How to focus stack

The general process with focus stacking is to take a series of images that cover different focus levels. Then stack the parts of the image that are in focus together to make a single in-focus image.

Focus stacking

Taking the photos

The macro photography setup in the graphics lab has a camera mounted on a copy stand and is controlled via a computer with the canon eos utility.

  1. Begin by getting the equipment up and running, frame your sample and get it in focus.
  2. At this point you should find an appropriate aperture value to use: a higher f number (smaller aperture size) will produce a larger depth of field but may reduce image quality (e.g sharpness). Use Depth of Feild (DOF) preview and take a few test shots to see what an appropriate f number is (recommended value is up to 20).
  3. Switch to DOF preview in the controls on the right hand side of the main window(see image below). This shows you what depth of field you will get for a particular f-number.
  4. Beginning with the top of the sample in focus step through the sample and count how many steps it takes to get to the bottom using the focus controls on the right hand side of the main window(see image below)
  5. Work out how many photos you will need to take so that every part of the sample is in focus in at least one photo. For instance if your sample is about 10 mm high and the region in good  focus in any given photo is  about 2.5 mm you will need 10/2.5=4 photos. It’s better to take more photos rather than fewer.
  6. Given the total number of steps and the number of photos required you should then be able to calculate how many steps to go between each photo. E.g. if you calculated 15 steps and you need 4 photos you will take photos every 5 steps  i.e. 0, 5, 10, 15.
  7. Beginning on the lowest part of the sample take a photo move through the steps, take another one and so on.

Once you get a better feel for this you will be able to do it a bit more intuitively.

Stacking the images in photoshop

  1. Open photoshop cs5
  2. Go to file>Scripts> Load Files into Stack
  3. Find the images that you took at various focus levels. Check the box for attempting to automatically align source images. This will add each image as a separate layer and attempt to automatically align them.
  4. Select all the layers in the layer panel
  5. Go to Edit>auto blend layers and choose stack images.

Photoshop will create a mask for each layer so that only the region in focus for a particular layer is visible.

You can now save you stacked image as a jpeg , tiff or whatever image format you prefer.

If there are issues with the stack you may need to take more photos or you can edit the masks manually.

Leave a comment