Focus Stacking for Macro Photography

Dean Wampler
The Backpacking Photographer
9 min readMay 4, 2024


I posted the following image on social media recently:

Macro photograph of tree lichen, Olive Park, Chicago. © 2024, Dean Wampler

That central “rectangle” is a little under a centimeter on each side. This led to a discussion about why “focus stacking” is necessary for an image like this and how to do it. A friend suggested I blog about it, so here we are…

Focus stacking is necessary when you can’t get all items in the frame in focus with a single exposure. (At least those parts you want; I wanted the white paper background to stay out of focus.) Sometimes a high f-stop will work, because it has greater depth of field (the range of distances in focus), but not always. When shooting macro, the depth of field can be very thin, just millimeters. Even in a landscape image, you might have some very close objects and distant mountains, all of which require a focus stack to be in focus.

In focus stacking, you take images at different focus points, ensuring the depths of field for the set overlap, then combine them with software, like Photoshop, where you pick the in-focus pixels from each image to create a blended image where everything is in focus.

Capturing the Images

Here is a setup in my office to photograph the head of my Zen Bigfoot, similar to what I used for the lichen:

Macro setup, described below.

I used the same tripod, macro focusing rail, camera, and lens to take the lichen photo, but I didn’t use lights. The two lights shown were made by Litra, which I really like, but sadly Litra didn’t survive the COVID Pandemic. (They were acquired by Logitech; the web conferencing lights Logitech has introduced recently are based on Litra’s technology.)

The camera is the Sony Alpha 7R V, but any camera with interchangeable lenses will work.

For best results, all the camera settings should be manual: focus, f-stop, shutter speed, ISO, white balance, etc., so there are no changes made automatically by the camera from one image to the next, e.g., because of slight changes in illumination. These changes would complicate merging the images. The only change I want from one frame to the next is the focus, under my complete control.

For each image, I used the settings f/9.0, 1/4 sec, ISO 100 and let the camera choose the white balance. I used a remote shutter trigger to avoid “bumping” the camera. (Using a 2-second delay would also work, if you don’t have a remote trigger mechanism.)

The lens is the Sigma 105mm F2.8 DG DN MACRO | Art lens. Note the working distance it provides, which can be nice for not disturbing insects, etc. Many “non-macro” lens available offer close focusing distances, so try what you have!

A tripod is necessary, but doesn’t have to be expensive or fancy. First, macro exposures sometimes require a long shutter speed, because the illumination per square millimeter can be low. More important for macro, you need careful control of the camera’s focus, meaning the camera’s position in space (and maybe time 🤓).

That’s where the macro focusing rail comes in, shown here attached to the tripod head, to which the camera is mounted. I’m using an older model of the NiSi focusing rail, which currently retails for about $200. (The rotating dial on their newest model, rather than a crank, shakes the setup less when you turn it!) You can find less expensive options, like this Sunwayfoto rail. Note the feet for when you just want to set it on a table.

Here is a closer view of the crank in action:

Turning the macro focusing rail crank. One revolution == 1 millimeter of travel

Each counter-clockwise rotation moves the camera one millimeter closer. Recall I’m using manual focus. I could try turning the focus ring on the lens to adjust the focus, but it doesn’t provide precise enough movement. Even if it did, I would have to find different spots on the object to ensure that I’m getting everything in focus in one or more images. Tedious at these small distance scales…

With the macro focusing rail, I first use the lens focusing ring to focus just at the closest point (the nose) or even a little bit before it. Then I take a picture, turn two rotations to move the focus plane two millimeters, take a picture, and repeat until I have images with every part of the object in focus.

Notice the red coloring in the image above? I have turned on focus peaking, which colors the parts of the image the camera believes are in focus. It’s not 100% reliable, but sufficiently accurate for our purposes. It indicates the depth of field is just a few millimeters thick here! As I move the camera, these red markers will move from front to back.

I stopped after 16 photos when the outline of Bigfoot, the farthest points from the camera were in focus. Turning two cranks, moving two millimeters at a time, meant I had plenty of overlap in the depths of field of the images. I could have moved farther between each image, but run the risk that some spot would not have been in focus in at least one image.
Note that just the tip of the nose is in focus in the following image:

One image, the first one with just the tip of the nose in focus.

One other important tip. As the camera was gradually moved forward, Bigfoot filled more of the frame. Hence, it was important for me to leave plenty of space around him at the beginning (as in this image), so I didn’t chop off the top of his head towards the end of the sequence, when the camera was closest!

In landscape focus stacks, the depth of field for any one shot will be much deeper, so you can create the focus stack using autofocus, selected by you at different points in the scene, or using the lens focus ring for manual focus. However, you may still see an apparent change of size in your objects. Many lenses show “focus breathing”, where it appears you are zooming slightly as you move focus forward or back. This is very annoying for videographers, but normally not so troublesome for photographers. Still, when focus stacking landscape shots, be careful about your edges!

Combining the Images

I use Adobe Lightroom to manage my photos and do many edits, supplemented by Adobe Photoshop. In this case, I loaded the 16 images in Lightroom to adjust the white balance (Zen Bigfoot is grey) and make other edits, then used Photoshop to merge the stack into the final image. If you don’t have Photoshop, Helicon Focus is one of several other options, which often provide more powerful features for trickier stacking situations.

If you are in Lightroom. Select the images to stack, then right click and select Edit in > Open as Layers in Photoshop:

Make sure you open as layers!

Opening as layers is important! Now in Photoshop, select all the layers on the right-hand side and use the Edit > Auto-Align Layers… menu option.

Select “Auto” in the dialog that pops up and “OK”. (The other options are for panoramas.)

This can take several minutes. Alignment handles the problem where Bigfoot is not at exactly the same position in all the images, as we discussed above.

Next, still with all the layers selected, use Edit > Auto-Blend Layers:

Select “Stack” and “OK”. (As for alignment, the other option is for creating a panorama.)

Hopefully you now see Bigfoot in all his focused glory!

Look at the layers panel on the right:

The layers now have masks.

The layers now have masks. Where a mask is white, the pixels are used in the final image. Where a mask is black, those pixels are not used. Note that the first four layer masks are all black: no pixels were used from these images! We could now select those layers, right-click and delete them.

Try clicking one of the little oval “eyes” next to a layer where its mask has some white. You’ll see pixels disappear in the blended image corresponding to the white in the layer’s mask. Now, in those spots, no pixels are used from this or any other layer. Reclick the eye to re-enable the layer.

If you look carefully at the blended image, you will see we are mostly in focus. Now we need to crop out the parts that remain out of focus in the margins. Recall that Bigfoot was smaller in the images at the beginning. We see the out of focus parts that were not present in the subsequent frames. Here is a close up of the lower-left of the image (before cropping):

Note the unfocused “border”.

So, we crop out the unfocused margin around the image.

The blend doesn’t always work perfectly. In my case, looking carefully at the outline of his head above and to the right of his left eye, he’s looking a bit blurry; the wrong pixels were picked by Photoshop here. (The blended image above is too small to really see this problem clearly.)

This post is already long, so I won’t explain possible fixes in detail here, but one technique goes like this. First, find the layer with the in-focus pixels that should have been used. Use the layer “eyes” to hide/show layers to make this process easier. Click the “link” between the image and mask in a layer to show all the pixels (i.e., disable the mask), then click it again to turn the mask back on. Once the right layer is found, make a copy of it and drag it to the top of the list of layers, which gives it the highest priority (i.e., the layers are “stacked”).

Now select the mask in that new layer. Select the brush tool and white for the foreground color. Finally, paint over the places in the mask that expose the pixels you want to see. In the blended image, you should see this part of the image now show the focused pixels.

Whew! Now you can do any other final edits, like spot removal, color adjustments, etc.

If you want to return later and do further work, save the image, but it will be very large on disk, because of all the layers, each of which holds information for a full frame. Instead, if you are done, select all the layers, right click, and select Merge Layers. Now the saved image will be smaller on disk, but you will no longer be able to work with the layers.

Final Thoughts

Like a lot of things, this all sounds intimidating at first, but the workflow is easy to learn by practicing a few times.

If you already have a camera, tripod, and a lens with “reasonable” close focusing distance, consider buying an inexpensive macro focusing rail and see what you can do! Also, buy yourself a Zen Bigfoot to keep you calm while learning.

Fixing the blend mistakes I mentioned is a little more advanced. There are online tutorials for this. Perhaps I’ll offer one in a subsequent post.



Dean Wampler
The Backpacking Photographer

The person who is wrong on the Internet. ML/AI and FP enthusiast. Lurks at the AI Alliance and IBM Research. Speaker, author, pretend photographer.