Focus Stacking For Tiny Subjects

Focus stacking is a photographic technique in which multiple exposures are taken of a subject, with the focus distance set to different lengths. These images are then composited together to create a final image with a greater depth of field than is possible with a single exposure. [Peter Lin] built a rig for accurate focus stacking with very small subjects.

The heart of the rig is a motion platform consisting of a tiny stepper motor fitted with a linear slide screw. This is connected to an Arduino or PIC with a basic stepper driver board. While the motor does not respond well to microstepping or other advanced techniques, simply driving it properly can give a resolution of 15 μm per step.

The motor/slide combination is not particularly powerful, and thus cannot readily be used to move the camera or optics. Instead, the rig is designed for photography of very small objects, in which the rail will move the subject itself.

It’s a tidy build that would serve well for anyone regularly doing macro focus stack photography. If you’ve been trying to better photograph your insect collection, this one is for you. It’s a valuable technique and one that applies to microscopy too. Video after the break.

https://www.youtube.com/watch?v=OzjuAQ87zjY

25 thoughts on “Focus Stacking For Tiny Subjects

  1. There are plenty of software packages available to help here as well. Some are open source and some are not. In addition, some are good and some are not so good and are slow and very old, not optimized software. I have yet to find one that is both open source, feature rich and solidly built. If anyone knows of one (I haven’t looked in 2 or 3 years now), please let me know!

    Here are a few that I have come across and seem to be fairly well known.

    https://github.com/pulsar123/Macro-scripts
    A set of bash scripts for post-processing of focus stacks for macro photography. Utilizes open source programs
    dcraw (https://www.cybercom.net/~dcoffin/dcraw/), Hugin (http://hugin.sourceforge.net/), and
    ImageMagick (http://www.imagemagick.org/script/index.php). Contains one C++ program written by the author (deadpixels.c).
    The scripts use BASH shell, so should work under any Linux distro and Cygwin under Windows.
    Pretty steep learning curve if you are unfamiliar with ImageMagick or BASH but pretty flexible.

    The same author put together https://pulsar124.fandom.com/wiki/Fast_Stacker which is a DIY cheap, fast, portable, and accurate automated macro focus stacking rail (based on Arduino microcontroller) which can be used with a wide range of photo cameras, and magnifications from standard macro (1:1) to extreme macro (up to 20:1). The same controller can also be used to control a motorized focuser for a telescope, allowing to memorize up to 24 different focusing positions, properly accounting for changes in temperature.

    https://en.wikipedia.org/wiki/CombineZ
    CombineZ is Free software image processing software package for creating extended depth of field images. It runs on Microsoft Windows. The current release is CombineZP (CombineZ-Pyramid), successor to CombineZM (CombineZ-Movie) which was based on CombineZ5 (designed for older versions of Windows and is no longer maintained). This software feels fairly dated.

    https://www.heliconsoft.com/heliconsoft-products/helicon-focus/
    Is a commercial offering that feels bloated but offers some good functionality and seems to be updated.

    1. I had a project this summer that needed a fast and robust photo stacking solution, but everything I found was either slow, clunky, or only ran on windows (commercial offerings included)- so I hired a freelancer to write a new one for me: https://github.com/PetteriAimonen/focus-stack it’s the best focus stacking solution I’ve ran across- commercial or open source. It’s written in C++, with GPU acceleration available. It’s command line based as well, so it can be implemented in other projects seamlessly. The windows version has a cute little executable that you can drag images onto and it will automatically focus stack them as well.

        1. I’m the freelancer involved; I guess I can disclose the amounts, considering it’s all open anyway and the project can be found on freelancer.com. My bid was 1000 USD; I ended up spending about 20 hours on it.

          Usually my prices are a bit higher for closed source projects, but this one had a combination of being able to release it as open source, having an interesting topic and having a clear and well defined scope. Especially the clear and well defined scope part: if your project scope is fuzzy, freelancers just have to add a larger margin for unexpected changes.

  2. If only the (or any) focusing lens is moved, this could be done fast in repetition.
    On modern smartphones, the focus is sometimes manually adjustable, could this be done with an app?

    1. My employer buys cameras that are refitted smartphone cameras specifically so we can do this kind of focus stacking. They come with either HID devices or UVC (linux) drivers that can adjust the focus. You send a number to the HID and it sets the focus. In the previous gen, that was a dimensionless number but the new cameras you can actually provide a distance in mm to focus upon.

      We are currently evaluating for replacing our current cameras the econ systems See3CAM_130 camera that has this kind of functionality. The datasheet says auto focus but also has a manual focus mode. https://www.e-consystems.com/13mp-autofocus-usb-camera.asp

      Note: no affiiliation or benefit to me if you get them from econ.

  3. It’s also worth checking if this functionality is already built in to your camera. On my camera (Fujifilm XT-3) it’s called focus bracketing and I would think it would be called something similar in other brands as well. I did a quick 30 second search and it looks like Panasonic and Olympus has it as well.

  4. I have a friend who is a big microscope buff. He will like this. Thanks.

    Some time back, I used a old CD transport, an Arduino, and Processing for some homemade scanner to look at interference in 3D. The code was set up so the Arduino/sled understood simple commands from processing. The code is show here.

    I found that with A4988 drivers, the little CD steppers were a little whiny, in the audible sense. I put a heatsink on mine for long-term operation.

    https://www.youtube.com/watch?v=ZH40mvSFI-g

  5. Magic Lantern, the open source firmware for Canon DSLRs can do this using the USM focus on the higher end lenses. Instead of moving the object, it moves the focus point. AFAIK, this can be set to do large numbers of stacked exposures.

  6. FWIW, there are scripts for CHDK that accept a focal range, then calculate and take as many shots as necessary to create a stack with the full range covered. I took ‘super macro’ image sets with my Canon S5 that ended up consisting of more than 20 shots each.

Leave a Reply to rasz_plCancel 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.