Macro photography under Linux

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Merging with enfuse

The standard tool for actually merging partial images into a composite is a free tool called enfuse [2]. This program is unique in that it has a special algorithm, known as the Burt-Adelson [3], which can detect regions that are in focus and also create seamless transitions in brightness across across multiple images. You need both of these capabilities when focus stacking.

The enfuse program is available as command-line software under Linux, Windows, the Mac. Using it is easy:

enfuse <options>... <input files>

The input files must be aligned exactly. Otherwise, you will get shadow images like the ones shown in Figure 4. Of course, TIFF files generated with align_image_stack make for a good choice. Normally, enfuse processes the images in the sequence you have specified. Sometimes, however, this does not make sense. If so, you can define the sequence as desired using the Response-Files . Response-Files are used in place of the input files and tagged with an @ , as in:

enfuse ... @<response-file>

enfuse was developed as a global program for merging images. It is also used for HDR images. Consequently, numerous options come into play for optimizing outcomes. Many of the program options, for example those for focus stacking, have strange default settings. Table 2 shows enfuse 's most important options.

Table 2

enfuse Options

Option Function
-l <level> Defines the number of levels used for the analysis. By default, enfuse uses automatic recognition ("auto") of the required level. Typically, you do not have to manually adjust the level in the range between 1 and 29. Larger values do not automatically produce better results, but they always use up much more computing time. Sometimes though it is also very helpful to merge using more levels.
-o <output file> Sets the name and the format of the output file. The default format is a TIFF. With the help of compression , you can also generate compressed TIFFs (compression= deflate, lzw, packbits, none ). jpeg=<compression> accepts compression levels from 0% to 100%.
-d <intensity> Defines the color intensity for TIFF output. Achievable levels of intensity include 8, 16, 32 and the variations r32 and r64 that are based on floating point numbers.
--show-image-formats Displays the supported image formats.
-v [<level>] Verbose – causes enfuse to annotate the work in more detail. This is often quite useful.

The options shown in Table 3 control the visual results. Many of the options rely on arguments in the form of floating point numbers between 0 and 1. When using the focus stacking function, you should always state the options --hard-mask and --contrast-weight=1 . The options --exposure-weight=0 and --saturation-weight=0 support these. Some of the options presented here can only be used in the command-line version as they are not currently supported by GUIs.

Table 3

enfuse Options (II)

Option Function
--exposure-weight= <floating point number> Determines how much the lighting will be considered. The default value is 1.0 for focus stacking.
--saturation-weight= <floating point number> Controls the influence of saturation on the algorithm. The default value is 0.2.0 for focus stacking.
--contrast-weight= <floating point number> Defines the influence of the contrasts. The default value is 0.1 for focus stacking.
--contrast-edge-scale= <floating point number> Controls edge recognition. The floating point number should normally fall in the range between 0.1 to 0.5. Each unit represents a pixel. A beginning value of 0.3 is recommended for experiments. This parameter should lead to improved sharpness under certain circumstances. Some users recommend not indicating the parameter --contrast-window-size= when using --contrast-edge-scale= . This parameter cannot be used with the enfuse GUI because it is only possible to enter whole numbers in this field. This restriction is a well-known bug.
--save-masks Prevents enfuse from automatically deleting masks that have been used. You can analyze, manipulate, and reuse these masks. The program stores them in <type>-<number>.tif format. You can assign another argument to this option with a different naming scheme (not the file names for the masks), which would then have to also be stated with --load-masks .
--hard-mask Uses "hard masks" as needed for focus stacking.
--load-masks Lets masks load instead of recomputing them. This means you can use masks that have been manipulated.

Apart from the options shown in Tables 2 and 3, there are a series of additional and very special options that can improve results:

  • --contrast-window-size=<size> defines the size of the "local contrast analysis" windows in pixels. An increase of 5 can sometimes improve the results, and it helps to prevent halos.
  • --gray-projector=<type> controls the way that the relevant regions of the images are computed during the contrast analysis. The default setting is average . Other possibilities include anti-value , l-star , lightness , luminance , pl-star , value , or channel-mixer . The last alternative is supposed to be the best, but it requires advanced knowledge of the channel mixer, which is controlled using three parameters. Otherwise, the l-star alternative produces fairly good results.

There are many other options that are only used in isolated cases. The original documentation [4] describes these in detail. Some tips on these parameters are also found in Pat David's blog [5].


Since most users do not get overly excited about using a command-line program, a graphical interface like MacroFusion has been available for some time for align_image_stack and enfuse . This Python program is a variation of the enfuse GUI, and it should run on all distributions. However, it offers only simplified options and possibilities. In particular, it lacks a capability for saving masks, and it also cannot load masks that have been saved. You will find more than enough instructions online, some of them excellent, for how to use this tool. Figure 7 shows how the interface looks when it starts.

Figure 7: The MacroFusion interface consists of multiple parts. The input files are above, the options are to the left, and the preview plus other functions are at the bottom.

MacroFusion combines align_image_stack and enfuse in a single interface, but it has only some of the functions you will need and others that you won't. First, you should load the desired input files using the Add button in the upper-left window. You can decide later which images you want to individually deactivate in order to test for effects. MacroFusion deposits the temporary files generated in this way in the ~/.config/mfusion/ directory. You should make sure that the directory has enough free space.

Next, you will need to select options for enfuse . Before doing so, you should activate the automatic alignment option using the Align checkbox, which is found under Align images . This section contains the options for align_image_stack . Automatic alignment is not always a good idea when you are dealing with high resolution images. See the "High Resolution Images" box for more information on this topic. Autocrop crops the output image so that all of the edges are clean. The other two options complement this feature.

High Resolution Images

Modern cameras like the OMD-5 (Mark II) are able to generate images with a resolution of more than 7000x5000 pixels. The RAW files from these type of images are about 100MB in size; the JPEGS are at least 20MB. However, some restrictions accompany images made with this camera. These include:

  • It is absolutely necessary to use a tripod, because the images are generated out of eight different parts.
  • Currently, you have to go through an additional step and manually activate the generation of RAW files.
  • You will need several seconds of time for each image. These images are therefore only suitable for non-moving objects.
  • The automatic focus stacking function can no longer be used. You will have to release exposures of the partial images manually.
  • The alignment (align_image_stack ) is still unable to handle these images properly. Therefore you should try to achieve the best possible alignment.
  • The processing times for larger images of this type is significantly longer. Batch jobs may be a solution.

Figure 3 shows that it pays to work with high resolution images.

Figure 3: High resolution images made with macro photography are impressive. This image was constructed from four layers and then manually reworked. However, you can clearly see that more layers should have been used.

There are three tabs in the middle of the window where you set the options for enfuse . These are the Fusion , Expert , and Configuration tabs.

Basic settings can be specified under Fusion . Figure 8 shows the settings that are important for focus stacking. You should refer to the information above to figure out whether you need other settings.

Figure 8: The basic settings for focus stacking are found in the first tab.

The Force HardMask option in the Expert tab is essential to achieving good results. Contrast window corresponds to the --contrast-window-size= and Gray Projector to the --gray-projector= options (Figure 9).

Figure 9: You should remember to activate the Force HardMask (--hard-mask) option in the second tab in order get good outcomes.

Normally, there is not much you will need to modify under Configuration if you do not have a large display screen and lots of RAM. If your screen and RAM are large, then you can adapt the preview size since the default size causes details to get lost. This means that problems might become visible only once the image is finished. The output options for JPEG and TIFF images are also found here. You might want to modify these. Copy exif info incorporates the EXIF data of the partial images in the newly generated all-in-one image.

You can generate a preview with Preview using the current settings. The Before/After buttons are there for you to figure out whether these settings are better than ones used before. One click brings up the result achieved with the previous settings in the preview window.

Images that have been manually generated with align_image_stack and enfuse often look better than those prepared with MacroFusion. This illustrates the fact that some of the necessary options are still not available and therefore cannot be activated. It is possible for you to exclude individual images from the processing by deactivating the images in the Photos window with a checkmark. In many cases though, this does not prove to be sufficient.

These types of mistakes are often found in high resolution images (see again the "High Resolution Images" box). They have to be more precisely aligned and merged in order to get a good results. To do so, it makes sense to use the -d (distortion) option and the possibility for manually processing masks that are both missing from MacroFusion.

Another peculiarity involves the sequence of the images. Normally cameras generate images in the correct sequence. If you generate the images manually, then the files have to be arranged accordingly. This is not possible with MacroFusion. Instead, you have to use the command line. However, it is sufficient to create the correct sequence for align_image_stack . The TIFFs that have been aligned can then be processed with MacroFusion.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $0.99
(incl. VAT)

Buy Ubuntu User

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content