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.

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

    regards,

    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
    Moe

  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 …
      Vince.

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

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

    Regards,

    Wes

  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.

    cheers

    jonas

  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 Ubuntu 12.04 64-bit).

    Also, pfscalibration version 1.5 seems to have a bug as noted at https://groups.google.com/forum/#!msg/pfstools/HZp69iwysa8/SsNi6pwcAoUJ I encountered this after the tif files were generated and then the batch/shell file would hang at “generating HDR”. Instructions on how to install version 1.4 can be found at http://linuxdarkroom.tassy.net/hdr-creation-script/installation-on-ubuntu/ After reverting to version 1.4 the process completed without problem.

    Last, since GIMP does not yet support full 16-bit image files, the batch file could also be amended to leave the 16-bit tif working file(s) (maybe just the enfuse.tif) to take advantage of the additional image data (for use in programs that currently support 16-bit formats). You may also want to consider support exporting the output in OpenEXR (both 16 and 32 bit formats) for people that want to take the images into more sophisticated programs.

    • Hi Anthony,

      Thanks for your feedback !
      I was going to remove UFRaw altogether and use dcraw directly instead.

      I’ll take your comments into account for a future release, maybe in a couple of weeks when I have time to work on the script again.

      Until then, Happy Holidays !

  15. Hi Vince

    Thank’s for the script … it works fine with jpgs but my Canon CR2-files don’t work 😐 (ubuntu 12.04 64)

    The tifs are generated, but then:

    Generating HDR
    TIFFReadDirectory: Warning, /path/to/picture1.tif: unknown field with tag 11 (0xb) encountered.
    TIFFReadDirectory: Warning, /path/to/picture2.tif: unknown field with tag 11 (0xb) encountered.
    TIFFReadDirectory: Warning, /path/to/picture3.tif: unknown field with tag 11 (0xb) encountered.
    pfshdrcalibrate error: input value higher than defined number of input levels (adjust the number of bits per pixel)

    And – because of that no pfs.hdr is generated … do you have an idea what I can do? Is there a workaround for that?

    THX sasch

  16. Great script. thanx!
    Works perfect also with Lumix GH2 images (.RW2), I had to add this to the allowed file formats.
    I had problems with the ufraw lens correction, so I turned it off “–lensfun=none”.

    I also added autocrop (-C) to the align_image_stack command, but at the end I need to “Fit canvas to layers”, because the jpeg is bigger than the cropped, aligned output. Maybe I can put that command to the Gimp-stacking script, but don’t know how…

    Then my suggestion is to generate a jpeg output from the xcf with “xcf2png” and “convert”. That is easy, but is senseless when the problem of the canvas size exists.

  17. Hi,

    if anyone like me is interested in using *tif as input, change line 119 to:

    if [ $filetype = “TIF” ] || [ $filetype = “JPG” ] || [ $filetype = “CR2” ] || [ $filetype = “NEF” ]; then

    Cheers!
    – See more at: http://linuxdarkroom.tassy.net/hdr-creation-script/installation-on-ubuntu/#comment-2372

  18. Hi there, I recently wrote an article about stacking/fusing bracketed photos (http://chymeric.eu/blog/2014/09/23/stack-bracketed-photos/) about a script I recently wrote (https://github.com/TheChymera/stackHDR). I linked to your article on this page to show your similar efforts, I would be very happy if you could link back!

  19. Awsome

  20. Hello Vincent,

    your code does the job, well done ! I have an issue which you may be able to help with, and may benefit others. When I apply the code to jpeg images coming from a simple webcam (I use fswebcam to acquire the data), the exif metada is insufficient for some of your code to work. I am thinking of manually updating the exif metadata, using exiftools, in order to fix the issue. Is this what you would recommend ? Which sections of the exif metadata is absolutely necessary ? On my webcam, I obtain the images with the different brackets using different values for the ‘exposure’ paramater.
    I know that the issue comes from the exif metadata, as your software works, error-free, on other jpeg images of mine, coming from a Nikon camera with extensive exif metadata.

    Many thanks and congratulations on your code,

    Martin.

    • Hi Martin,
      The only place where Exif data is involved is when the jpeg2hdrgen command creates the hdrgen script.

      The content of this script is basicalle the following:
      path_to_an_image inverse_of_exposure_time_in_seconds aperture_size iso_speed 0

      Therefore, I’d try to set the ISO, exposure time and aperture in your images. Fix two of them and make the 3rd one different to reflect how you capture your image with the webcam (gain, exposuretime or otherwise)

      Best,
      Vincent.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.