Focus Stacking is a digital image processing technique which combines multiple images taken at different focus distances to give a resulting image with a greater depth of field than any of the individual source images. Focus stacking can be used in any situation where individual images have a very shallow depth of field, is especially used in extreme macro photography. There are two basic ways to make this technique, change the focus or change the distance to the subject. In this article, I not explain the technique, in Internet have a lot of great explains of this technique, for example the Pat David article that inspire me to write this article.
In this case we will change the focus, which is not the best option but if it does not require large investments to automate. This article has two parts, the first capture the images and the second the processing.
I. Automated capture
For the first part we use DslrDashboard, is a software for remote control or our camera in Android, actually is multiplatform (Linux, Windows y mac). Allows the control by USB port or by wifi, this last with the NIKON wifi modules, or connected to a server with installed DslrDashboard, for example a old mobile, a raspberry pi or a router with OpenWRT firmware installed, or a specific module like the Total Remoto MK-1
- A devices with DslrDashboard
- A camera supported by DslrDashboard(Nikon y Canon have a lot of models supported)
- A tripod
To start, connect the camera to the device, in my case I use my tablet with usb otg, select the closet focus point and hit the Autofocus button. Now we have to see how many steps we need to focus, so we use manual focus controls on the bottom of the Live View.
The arrows buttons on the bottom side, the double go to the end and the simple move the focus ring the number of defined steps, these are indicated by the number between controls and can be varied with the attached slider.
Depends of your lens, the number of steps change, you select a round number, not too small and changes the focus with the simple arrow until you see with the far side focused. Each time you press the button is a shot to make with the selected focus step. If you appreciate the images not have the correct dof reduce the focus step.
With these numbers in mind, reset the focus, and then press the button for focus stacking, enter the number of shots to be taken (the number of keystrokes that realizasteis before) and the focus step selected. Select direction according to how you made the initial focus and hit the start button. The camera started working and the display will indicate the number of photography that is performing. Once the process is complete the software will return to its initial position.
With this, we are ending the capture, upload the images to a directory in you computer to start the next part.
II. Process automatization
To make focus stacking exist specialized software like Zere Stacker, probably the best, but not is open source (for testing exist a trial version for 30 days), so the best way to do this with open source software is used enfuse, a wonderful piece of software that has multiple uses, the best is review the documentation for see the possibilities. The articles of Edu Perez y Patrick David have a good explain in the use of enfuse for focus stacking.
As the complete process can be tedious, requiring several steps and they are slow, I decided to automate with script to perform the entire process transparently. The script makes the raw revealed, the alignment and the fusion of images.
Copy the file focusStacking.sh in the bin directory of the user home and assign the execution permission with chmod +x focusStacking.sh
The scrip need all
The script requires that the images are all the same type, it supports jpg or raw files, are processed in a directory and is need they does not contain any other files. The process will create two directories, tmp for store the process files to make the stacking and out for save the output image, the process files and the output image are TIFF of 16 bit to maintain the highest quality. To run it, just execute in the directory of images to be processed this command
- -a Align images (Optional, but recomended )
- -q Quiet
- -h Display the help
- -d Parameters for process with dcraw, quoted the parameters. “-4 -T” is required for Tiff. By default use “-4 -T -w -p embed” .
- -w “Contrast Window Size” for enfuse
- -e “Contrast Edge Scale” for enfuse
- -g “Gray proyector” for enfuse
A good starting point to adjust the result is to read David Pat’s article, which explains how these parameters work.
For example I using this parameters in the sample process:
focusStacking.sh -a -g l-star -e 0.3 .