The tulips have started to bloom at the annual Skagit Valley Tulip Festival. Long rows of flowers are a perfect subject to learn or practice focus stacking.
What is focus stacking and why is it needed?
Sometimes you are trying to capture a scene that is in focus from immediately in front of you to infinity. Long rows of flowers is one such scene where I like to use focus stacking.
Given the large depth-of-field, most camera lenses, even at extremely small apertures like f/16, f/22 or f/32, will not be able to have an entire scene like this in focus. Even when the optimal “hyper focal point” is set, at these small apertures there is much more diffraction that decreases the sharpness of the final image.
To maintain optimal focus and sharpness, focus stacking is a technique where you take a series of photos focused at varying parts of the scene and combine them into one image that is completely in focus.
Tilt-shift lenses are able to alter the plane of focus to potentially achieve this in one shot, but most photographers do not own them, and tilt-shift lenses can be a genuine pain in the butt to operate in the field. Even when set correctly with the optimal “hyper focal point,” this technique can also suffer from diffraction.
How to take focus stacked images
It is important that your camera does not move when taking a series of images that you intend to focus stack. A sturdy tripod is essential to avoid difficulties in merging images that have slight differences in perspective. Using a timer or cable release to trigger your shutter also helps ensure that you do not move the camera.
If you are using one of the latest Nikon cameras like the D850, Z6 or Z7, there is a special focus shift function that I’ll get to in a bit. Let’s start with instructions for most cameras.
With your camera on a tripod, compose your scene. For landscape images, use an aperture in a range where the lens is in sharpest focus and avoids the diffraction present at very small apertures, so something like f/8-f/11. While wider apertures with shallower depths of field may make the focus stacking process better by increasing the variation between sharp and soft detail, it can be very difficult to accurately take a series of images at wide apertures like f/5.6 without missing a “slice” of focus area.
Since you will be blending the images, it is also important to ensure that exposure settings like ISO and shutter speed are also fixed throughout the series of photos. If outdoors, you should take the series of photos in fairly quick succession. You want to avoid changes in lighting, exposure or the sky over the series of photos that will make it difficult to blend images together.
For most DSLR and mirrorless cameras, using manual focus will be easiest. Focus on the nearest element in the scene and take a picture. Now move the focus ring of your lens a small increment towards infinity to focus on a part of the scene that is slightly further away and take another photo. Repeat this process until you have reached either the furthest element in your scene or infinity focus. Be sure that you have one picture at infinity focus.
Users of the latest Nikon cameras like the Nikon D850, Z6 or Z7 currently have a benefit over other camera manufacturers. A built-in mode called “focus shift shooting” allows you to automate this process.
If you have one of these Nikon cameras, remain in auto-focus mode, compose your shot and focus on the closest part of the scene. Then enter “focus shift shooting” mode, chose the number of intervals and width of those intervals and choose start. Because this process is automated, you can use a slightly wider aperture like f/5.6-f/8.
The camera will take a series of photos and change the focus depth at each exposure. The camera will take the lens beyond infinity focus, so you will want to discard the extra photos at the end of the series that go beyond infinity before merging the images. Take one additional picture at infinity focus to be certain that you have it.
Motion in the scene can be your enemy. Flowers, leaves or plants swaying in the wind, or other objects moving in the scene are difficult or impossible to merge in post-processing without odd artifacts or extremely tedious manual edits. Smooth motion, like that of flowing water is easier to merge.
On landscape photos you will likely end up with a series of ~2-6 photos, depending on aperture used and the depth-of-field you are trying to capture. When using this technique for close-up macro photos, or when using longer focal lengths, a larger number of photos with narrower areas of focus will be necessary.
Processing focus-stacked images
Synchronize edits in Lightroom
I use a combination of Lightroom and Photoshop to process my focus-stacked images.
Starting in Lightroom, identify a focus-stacked sequence of photos. Edit one of those to your liking, making adjustments to color temperature, exposure, contrast, highlights, etc. This is also the point where I apply any lens correction, sharpening, noise reduction and spot removal.
Once the Lightroom edits are complete, synchronize the edits to the series of focus-stacked images. The final result should be a group of photos that are identical, other than their focus points.
In Lightroom, highlight the series of photos. Right-click and choose Edit In > Open as Layers in Photoshop to bring each photo in to Photoshop as an individual layer.
Remove focus breathing with auto-align
Most still camera lenses will exhibit some amount of focus breathing. Focus breathing is when the focal length of the lens changes when focusing at different depths.
In your series of focus-stacked images, this may be subtle or it may be obvious. As focus changes, you will see that the images appear to zoom in or out. Sometimes it is a few pixels, but sometimes it is quite a bit more. This is entirely dependent on the lens that you used. Let’s look at an example.
I own two 70-200mm lenses. One is the Nikkor 70-200mm f/2.8E FL. I also own the smaller/lighter Nikkor 70-700mm f/4G. Both are very sharp, but the f/4 version exhibits quite a bit more focus breathing that the f/2.8E. After auto-aligning a series of images at different focus points, you can see the effect focus breathing has on the changing scale of the pictures.
- 70-200mm f/2.8E
- Full resolution: 8279 x 5519 pixels
- After auto-align: 8255 px (-24 pixels) x 5503 px (-16 pixels)
- 70-200mm f/4
- Full resolution: 8256 x 5504 pixels
- After auto-align: 8094 px (-162 pixels) x 5395 px (-109 pixels)
Photoshop can help correct this by auto-aligning the images. Select all of the layers that you brought in from Lightroom and choose Edit > Auto-Align Layers. For Projection, Auto will usually give great results, but you can also use Collage, which allows for image rotation, scale and translation. The resulting layers will be scaled slightly to align the image and remove any changes in scale, perspective or distortion caused by focus breathing.
Blending focus-stacked images
Photoshop’s Auto-Blend Layers command allows you to blend multiple images with different areas of focus.
Once your layers are aligned, select the same layers and choose Edit > Auto-Blend Layers. Choose Stack Images for your Blend Method. Also choose Seamless Tones and Colors and click OK. This process may take awhile.
The end result is a set of layer masks applied to the various areas of focus in each layer. These are normal Photoshop layer masks, so you could alter or tweak them if the initial result isn’t to your liking.
Fix mistakes in the sky when auto-blending
The process that Photoshop uses to focus stack images is to compare areas of micro-contrast in each area of the photo to determine which areas are in focus and which are not. This works great for many parts of the scene, except for the sky.
A clear sky or even a cloudy sky will have no discernible changes in micro-contrast when it is in focus or out of focus. Because of this, focus stacking software may mistakenly blend parts of the sky using the wrong layer.
Inspect the layer masks applied to the layer that is at infinite focus to see which layer or layers are being used for the sky. Clicking the eye icon next to each layer on and off can help you to see which layer(s) are being used in the sky.
In some cases, despite blending mistakes in the sky, the image may look perfectly acceptable as it is.
In cases where blending mistakes in the sky are noticeable, this can be fixed by altering the layer mask for the sky.
First, chose the layer that is at infinity focus. Move it to the top of the layer stack, if it is not already there. Turning off visibility of the other layers will help you to see the exact layer mask that you are working with.
Now highlight the layer mask that should include the entire sky. Choose a brush tool and make it white. Now brush in all of the areas of the sky that are masked out.
As you brush with a white brush, you will see that the transparent areas now begin to reveal the photo. Ensuring that this layer is at the top of the layer stack will make sure it is visible for the sky versus the lower layers of the image.
Clean up the edges
If your lens exhibits quite a bit of focus breathing, the edges of the merged photos are going to show transparent areas. This is because auto-aligning the images caused changes in scale, leaving transparent areas that need to be cropped from your final image.
You may also find that the auto-align/auto-blend process leaves artifacts at the edges of the photograph that appear to be out of focus because of the auto-align process. Zoom to at least 100%-200% and inspect each edge of the photo.
The quickest solution is to crop out any edges that did not satisfactorily merge because of changes in scale. For some lenses with minor focus breathing, this may only be a few pixels. For lenses with heavier focus breathing, you may need to crop a little bit more.
Once you are happy with the merged image, you can flatten it to remove the layers and save your final image.
Other focus stacking solutions
Photoshop is not the only software tool available for focus stacking. Software like Helicon Focus and Zerene Stacker can focus stack images, and do offer more control and tweaks for the image blending process that may provide better results. However, for many uses, the focus stacking capabilities of Photoshop are quite powerful and useful.
Thanks to March Muench of Muench Workshops, who has been honing his focus stacking techniques for years longer than most of us, for tips and suggested edits on this post.
Focus-stacked image gallery
Here are some other focus-stacked images that I took at the Skagit Valley Tulip Festival.