HDR Creation Script

A while ago, as I was exploring the world of HDR images and how to create them on Linux, I stumbled across the photoblog of Edu Pérez and was very interested by the workflow he used to create HDR images on Linux.
He even put most of it together in a convenient script. Based on his work, I created my own script to align more closely to my requirements.
For instance, I happen to shoot in JPG sometimes and needed the script to support this format as well as RAW.
To streamline the process even further, I also scripted the Gimp part of the workflow so the script actually generates an XCF file containing 3 layers:

The layer stack in Gimp

  • An exposure blended image produced by enfuse as the background
  •  In HDR image tone-mapped using the mantiuk06 operator in a layer in Soft-Light mode and 50% opacity
  • An HDR image tone-mapped using the fattal02 operator in a layer in Overlay mode


The script is invoked from the command-line:

Usage: createHDR.sh [OPTIONS] DIR
-a Align the pictures first
-g{val}    gamma option for RAW conversion (–gamma={val} — DEFAULT=0.45)
-s{val}    saturation option for RAW conversion (–saturation={val} — DEFAULT=1.0)
-e{val}    exposure compensation option for RAW conversion (–exposure={val} — DEFAULT=0.0)
-l{val}    linearity option for RAW conversion (–linearity={val} — DEFAULT=0.10)
-c{path} Configuration file for ufrraw IDFILE.ufraw
-q            Quiet
-k            Display progress information with kdialog
-h            This help

The script will make sure that only one type of file is present in the directory.

If -a is passed as an option, the script will first align the images using align_image_stack command provided by Hugin.

Here are a couple of images produced by this script out of a series of 3 bracketed images:

Nice old town

Promenade des anglais

The latest version of the script can be downloaded from the attachments section at the left of this page !
Update (23 Sept 2009): updated the script to v1.1. See changelog in the script itself.
Update (29 Sept 2009): updated the script to v1.2. See changelog in the script itself.
Update (2 Nov 2009): updated the script to v1.3. See changelog in the script itself.
Update (12 Nov 2009): updated the script to v1.3.1. See changelog in the script itself.
Update (20 Sep 2009): updated the script to v1.4. See changelog in the script itself.
Update (04 Oct 2010): updated the script to v1.4.1. See changelog in the script itself.

If you like this script, feel free to leave a comment !

You can find installation instructions for Ubuntu here and for Fedora here.

How to run the script on several directories

Say you’ve generated dozens of bracketed series and have isolated them in their individual directories using my other script.
You don’t want to have to run the createHDR script manually for each stack !
So I just put together another utility script that will do just that:

Usage: processBrackets.sh [OPTION] DIR
–quiet   -q  Quiet
–kde     -k  Display progress with kdialog

Just make sure sure you have the createHDR.sh script on your path.

Optionally, if you’re running KDE, you can copy the attached .desktop file to the folder services/ServiceMenus of your kde4 install and you’ll end up with a contextual menu when you right mouse click on a folder from your file explorer …
On my machine, the file is /usr/share/kde4/services/ServiceMenus/vinceHDR.desktop

If you run into problems, you can send me an email at photo@tassy.net and I’ll help you out.

CC-GNU GPLThis software is licensed under the CC-GNU GPL version 2.0 or later.

  37 Responses to “HDR Creation Script”

  1. Wow! It looks really nice, but unfortunately it doesn’t work on ubuntu 11.10. The script ends with an error at line 117.

    createHDR.sh: 117: Syntax error: “(” unexpected

    Do you have any suggestion how I can fix this? I’m using bash version 4.2.10(1). I’ve installed all the tools that you indicated.


    Dirk Boon

  2. I have also a problem at line 117.
    Any glue?

    • Hello Maria,
      could tell me what is the error you’re getting ?
      Also what Linux distribution are you using ?
      You can mail me directly at photo@tassy.net

    • Hello Maria,

      I’m guessing you’re running the script with sh and not bash and that this is what causes the error …

      so either run: bash createHDR.sh myfolder

      or, what I do, make the script executable (chmod 755 createHDR.sh) and then run it as ./createHDR.sh -a myfolder

      note it is a point slash prior to the name.

      The first line in the script indicates that it should be run using bash rather than sh so runnin it this way will take care of it … also, this way you can move the createHDR.sh file to /usr/bin and this way you can call it from anywhere just by running: createHDR.sh -a myfolder

      Let me know if it fixed your problem !

  3. Dear Vincent

    Really great scripts and quite useful. I hope I can get it working on my Ubuntu (11.10) box! I get the following error massage when I run your script, would you have any clue why:

    ‘tif files unsupported. Compile pfstools with ImageMagick or libtiff’

    I looked up pfstools website and help but there is no clear instruction on how to complile pfstools with ImageMagick or libtiff. Any help will be greatly appreciated.

    Best wishes and thanks

  4. Heya, handy script. I did find it gave an error though

    velofille@awesome:~/Pictures$ ./createHDR.sh -a Photos/2012/06/HDR-hamilton-gardens/hdr-1/
    Files are CR2
    Parsing EXIF information
    Devloping RAW files
    Aligning images
    Generating Enfused image
    Generating HDR
    Missing image '/home/velofille/Pictures/Photos/2012/06/HDR-hamilton-gardens/hdr-1/AIS_*.tif' at /usr/local/bin/pfsinhdrgen line 61, line 1.
    pfshdrcalibrate error: at least one image required for calibration (check paths in hdrgen script?)

    After digging around i see that it needs ufraw-batch installed under ubuntu – so you may want to update the tutorial to account for that 🙂

  5. For some reason every single image is coming out with a heavy blue hue. Unsure why at this stage, will look into it and see if i can figure it out

  6. Figured out my blue hue problems – and old ~/.ufrawrc – now removed 🙂

    • I’ve had that issue before …
      Problem with calling ufraw from the command-line is that you can’t zero out all the settings you may have done in the UI 🙁
      That’s wy I’ve had on my to-do list to update the script to use dcraw directly instead of ufraw-batch …

  7. Hi, it looks great, any chance I can get this working on Centos?

    • Hi Rob,
      there’s no reason why it shouldn’t work on CentOS.
      I don’t have one handy to test but you can gisve it a shot ! Look at te Ubuntu and Fedora instructions to get an idea of the needed dependencies and you should have it working easily.
      Let me know how it goes !

  8. […] then found this script which saved me having to write anything else much http://linuxdarkroom.tassy.net/hdr-creation-script/ .This does require a few things installed as dependencies, but nothing overly […]

  9. […] This is an HDR composite created with my Linux script available here. […]

  10. […] This is an HDR image based on 3 exposures and processed with my special recipe. […]

  11. […] This is a 3 frame HDR processed with my home made script. […]

  12. Hi Vincent,

    Interested in your ‘HDR Creation Script’. Is it still available?



  13. Hi Vincent,
    I have been using your scripts (sortBrackets, createHDR) a lot during the last two years. They produce really awsome results and I can spend the time shooting rather than tweeking 😉

    However somthing in the workflow has stopped working. The hdr_mantiuk06.tif is produced but looks very weird. When it comes to fattal02 the script just fangs. Du you have any idea what is causing the problem?

    My bracketed photos are canon raw “CR2” (have always used that without problems). If I try whith jpg’s there is no problem. I am on ubuntu 12.10.



  14. Thank you for taking the time to develop and post this batch file.

    The latest version of the createHDR.sh seems to contain an error (or the input parameters on ufraw-batch may have changed). Instead of “tiff” the output type should read “tif”. Also, ufraw may not have the tiff conversion libraries enabled so an easy way to check is to call ufraw-batch directly in a subdirectory with some test files. For instance “ufraw-batch –out-type=tif –out-depth=16 *.CR2” from within the subdirectory where the test CR2 files are located. If the file conversion cannot be completed then you will need to rebuild Ufraw (or obtain a copy that has the tiff libraries active). Useful unstructions were found at http://sourceforge.net/projects/ufraw/forums/forum/434060/topic/53401 (it worked for