Focus Stacking automated with Linux

June 1, 2014 Posted by ramso

 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

For advanced use, and better explains of all the features, I recommed read the Instant Guide to DSLR Dashboard by Dmitr Popov


  • 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.

Live view

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.

Focus stacking parameters

Focus stacking parameters

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.

Clossing focus

Clossing focus

No limit focus

No limit focus

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.


  • Dcraw for the raw process
  • Hugin for align the images
  • Enfuse for fusion the images


Copy the file in the bin directory of the user home and assign the execution permission with  chmod +x


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: -a -g l-star -e 0.3 .

Result processed

Result processed


Download “Focus Stacking Script” – Downloaded 691 times – 4 KB


CBT Service Menu 1.4 lanzado

January 7, 2012 Posted by ramso

A new version of Comic Book Transformer Service Menu is available for download.New Features in this version:

  • Compress files without the directory structure
  •  New profiles:
  • Android Tablet: 800×1280
  • Kindle DXG: 824×1200
  • Crop Double pages in single pages, if possible to control in the script
  • Fix bug with spaces in directory name for scale options (more…)
  • Linux embebido

    September 25, 2011 Posted by ramso

    I write this article because all the statistics i see about the use of operating systems never see reality. All the statistics say that the desktop is used very little, I don’t know how obtained this data, but it seems a very low percentage for what I see daily. In  server is in first place, thanks to Internet servers and infrastructure servers in enterprise environments. In mobile environment dominates the market with Android, but there are other alternative like WebOS or maemo/ meego, badly exploited by the manufacturers. (more…)

    CBT Service Menu 1.3.0 disponible

    February 20, 2011 Posted by ramso

    A new version of Comic Book Transformer Service Menu is available for download.

    New Features in this version:

    • CB7 full support. Require the p7zip package.
    • Custom scaled for comic.


    New Version of CBT Service Menu

    February 12, 2011 Posted by ramso

    A new Version of the Comic Book Transformer Service Menu for KDE is avaible now. This version fixes several bugs and included the following new features:

    • Progressbar for multi files transform
    • Convert pdf to CBR and CBZ
    • Scale for tablets 600 x 1024

    For more information see the original post


    Download “Comic book Transformer Service Menu V1.3” cbt_servicemenu_1.2.0.tar.gz – Downloaded 843 times – 2 KB

    Comic Book Transformer KDE Service Menu

    August 28, 2010 Posted by ramso

    This KDE4 Service Menu is designed to make more easy the generation of Comic Book files in CBR, CBZ or PDF Formats. Provide options to scale to different resolutions and transform to gray for use in ebooks.


    • Convert Images directories to CBR, CBZ o PDF files
    • Convert  CBR o CBZ files in  PDF
    • Transform to gray scale
    • Scale to 1024×768 or 800×600


    In Dolphin select a directory or CBR, CBZ file, in actions menu select Comic Book Transformer. In the new menu select the output format for your file.

    Menu of Comic Book Transformer

    In you need transformation options, select the item ending in […options] for your output type.

    Options for The transformation

    Select the type of the output transformation an press Accept. A dialog  inform you with the result of the transformation.


    Install this packages

    • Zip
    • Unzip
    • Rar
    • Unrar
    • ImageMagick


    Untar the file

    Home installation:

    – place the desktop files in $(kde4-config –localprefix)/share/kde4/services/ServiceMenus/
    – place the cb_servicemenu script file in a directory in your path (I have ~/bin)

    System-wide installation:

    – place the desktop files in $(kde4-config –prefix)/share/kde4/services/ServiceMenus/
    – place the cb_servicemenu script file in /usr/bin/ or /usr/local/bin/


    Last version

    Versiones anteriores


    Generador de documentación en formato DITA

    August 7, 2010 Posted by ramso

    This project is intended to generate documentation of standard models in the DITA output format. There are currently no open source tools to facilitate this work and that’s the main reason for initiating this project.

    The choice of DITA as the output format is due to its flexibility as it is designed for generating technical documentation, because this is simpler than docbook and is better suited to my goals. (more…)

    Mi Flickr

    July 3, 2010 Posted by ramso



    Jardin Japones en Toulouse

    July 3, 2010 Posted by ramso

    [nggallery id=2]


    Configurando Mythtv Backend

    November 25, 2008 Posted by ramso

    Bueno, pues comenzamos… ahora sabremos si todos los pasos previos estan bien realizados.

    Antes de empezar, seria conveniente que comprobasemos que el equipo detecta correctamente nuestra tarjeta de television TDT. Hay dos maneras, la primera seria tan sencillo como ir a Yast2–>Hardware–>TV Card. Si todo ha ido bien, al abrir “TV Card” os tiene que aparecer la tarjeta de video auto detectada por el sistema. Podeis pulsar el boton edit para apuntar algunos parametros que pueden sernos utilies en la configuracion de mythtv. (more…)