What is focus stacking in photography?

Focus stacking

Focus stacking is a post processing technique where several images of the same subject and scene is combined in post processing, to make all of the image sharp rather than having the sharpness defined by the depth of field.

Focus stacking is especially useful for macro photographers, because the depth of field becomes very very shallow when the lens focuses extremely close to the subject, but also landscape photographers and architecture photographers can benefit from focus stacking.

Example

Look at the silly picture below, taken in my office. In the foreground and in focus you have the mad cow and in the background and out of focus, my glasses, a computer screen and a lamp with a bright light.

Below a picture of exactly the same scene. Nothing has changed, other than the focus has been moved from the foreground, the cow, to the background, my glasses. Notice how blurred the cow in the foreground is.

The trick is now to combine the two so that you pick the parts that are sharp and use these in a combined picture. You can do this in post processing software like Photoshop. I open the two images as layers in photoshop.

First step is to make sure the pictures sit right on top of each other, and Photoshop has a function to secure this (edit, auto-align layers).

Second step is to ask Photoshop to create masks to combine the two images into one (edit, auto-blend layers, stack images). You can see in the two images below how the top one selects the cow, whereas the bottom one selects large parts of the background including the glasses. What is white is included and what is black is masked out.

The resulting image is shown below. As you can see, both the cow and the glasses are now sharp, which is exactly what focus stacking can do for you: it makes it possible to have both objects very close to you and objects very far away appear sharp in the image.

If you study the image carefully, you will notice that the lamp looks a bit funny. It is as if the edge between the light and the dark part suddenly has a half circle to the left – just above the head of the cow. This is due to focus breathing – the lens used here suffers from slight focus breathing, meaning that the angle of view changes ever so slightly when the focus changes. This error makes it impossible for Photoshop to combine the images properly as the size of the lamp varies between the two images. So it is important that there is absolutely no focus breathing for lenses used for focus stacking!

Related reading

What is focus breathing?

What is Depth-Of-Field?