Better Macro Images With Arduino Focus Stacking

If you’ve ever played around with macro photography, you’ve likely noticed that the higher the lens magnification, the less the depth of field. One way around this issue is to take several slices at different focus points, and then stitch the photos together digitally. As [Curious Scientist] demonstrates, this is a relatively simple motion control project and well within the reach of a garden-variety Arduino.

You can move the camera or move the subject. Either way, you really only need one axis of motion, which makes it quite simple. This build relies on a solid-looking lead screw to move a carriage up or down. An Arduino Nano acts as the brains, a stepper motor drives the lead screw, and a small display shows stats such as current progress and total distance to move.

The stepper motor uses a conventional stepper driver “stick” as you find in many 3D printers. In fact, we wondered if you couldn’t just grab a 3D printer board and modify it for this service without spinning a custom PCB. Fittingly, the example subject is another Arduino Nano. Skip ahead to 32:22 in the video below to see the final result.

We’ve seen similar projects, of course. You can build for tiny subjects. You can also adapt an existing motion control device like a CNC machine.

17 thoughts on “Better Macro Images With Arduino Focus Stacking

    1. Stacking software is used to combine the images. Using it is a bit of an art as it can produce strange, surreal results if you get the settings wrong.

      Alan Hadley’s Combine ZP is popular (and free), while Picolay (also free for non commercial use) has its admirers.

      Google “free image stacking software” for a more complete list, downloads and manuals.
      Be warned, much of this software is Windows only.

    2. Stitching scanned images also uses software that takes account of corner distortions when photographing a large object. As I have never used it (I go deep rather than wide), I can only suggest that google might be your friend.

      Flat bed scanners used to come with software such as scan ‘n’ stitch, but they didn’t have any correction for the field curvature found in cameras.

    3. Photoshop will do exactly that process, each image in a stack is auto evaluated and a mask is applied so the sharpest area shows. The process is only three steps 1) Load all images into stack 2) Auto auto-align stack (just in case there was any slight movement that changed alignment) 3) Auto-blend stack

    4. I do a lot of focus stacked macro photography. Photoshop can do it but it’s slow and not very accurate. Helicon Focus is my preferred tool. It’s not free but it’s the fastest that I’ve found and is really easy to use. The latest version supports the M1/M2 chips on Macs.

  1. It would have been nice to see how he merged the individual images. Does it require dozens of images or just a handful? How automated is the merging process? Then you could assess whether the choke point is in the image acquisition or the post processing.

    1. See my previous for Image Stacking software.

      Mileage varies with the number of frames to stack, the size of those frames and your choice of software and settings. The software tends to run faster than image acquisition if you allow settling time when moving the sample/camera.

    2. In Photoshop the process is fairly automated, all frames are loaded as a stack and auto-blend with auto-align pretty much takes care of the heavy lifting (a layer mask is created on each image in the stack so the sharpest area remains visible).

    3. The video was focusing (pun intended) on the rig and not on the stitching. You can find the answer on Google in like 2 seconds by searching “how to merge images by focus stacking”… The number of images depend on many parameters such as the magnification, aperture, the depth that you want to cover and so on, as others also said it. There will be another video on this (or actually a new) rig relatively soon and I will include the stacking process in it as well.

    1. True, however, a lot of lenses will change actual magnification when changing the focus point. It’s called “breathing”. Plus, moving the camera allows very precise control of the focus point when stacking hundreds of images with very thin depth of focus. Also, that works with any camera.

    1. That’s not how optics work. Below a certain aperture (f8-f11-ish), diffraction will play more and more role and your image will start to soften. Also, even at narrower apertures, you won’t get wide enough depth of field so you would need to do stacking anyway.

Leave a Reply to alialialiCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.