Skip to main content
Participating Frequently
August 17, 2013
Question

Batch HDR Merging/Toning Script

  • August 17, 2013
  • 31 replies
  • 46037 views

I've seen a number of different posts on these forums about trying to do this and I never really found a complete and suitable solution. It also has really annoyed me that adobe never implemented this (and it's not possible to do with actions because the action just runs a script and you can't record the HDR toning settings, the dialog always pops up, its in the script). So I finally had some time to get my hands dirty with ExtendScript and I have created a fully featured script complete with UI that allows batch creation of HDR tonned images in photoshop.

The code I got working from various snipets of code I found around the 'net and single stepping through the MergeToHDR.jsx script that is built into photoshop.

This has only been partially tested on photoshop CC on a mac. Hopefully I made it portable enough and it will work on windows and older versions. I don't think the MergeToHDR script has changed much in the last several versions (and that is mainly what I call to do the work) so I think it should work. If you have issues please let me know.

My motivation for this script was coming up with a way to do batch HDR toning for timelapse and so this script's features lean toward using it for that end. I really didn't want to buy another separate program for doing this like photomatix, when I knew it should at least be possible to do in photoshop.

I uploaded the script to github:

https://github.com/davidmilligan/PhotoshopBatchHDR/blob/master/Batch%20HDR.jsx

How to use:

  • Drop the script in the '[photoshop folder]/presets/scripts' folder and restart photoshop if it is already running.
  • The script should appear as a menu item under File>Automate>Batch HDR...
  • A dialog will appear where you specify all the settings for the batch
  • Input Section:
    • Click browse and select the source folder that contains the images to be merged/toned
    • Specify "Number of Brackets" this is how many separate images to group into a single HDR output image (the script will group the images in the source folder in order based on this parameter). You can use a value of 1, which means each image in the source folder is separate and will be toned and output. (I find that many times when shooting RAW, 14 bits is ample to capture the full dynamic of the scene, so I do not waste storage space and shutter acutations using more than one exposure, just make sure to ETTR, also post-processing with this script will be faster)
    • If there are other files in your source folder (for example .xmp files) that you need to exclude you can specify a filte. For example: *.cr2
    • Typically for timelapse you are using a tripod and do not need to have photoshop align the images, but I provided that capability for anyone who might need it b/c it was easy to enable. Note that enabling this will make the process MUCH slower.
  • Toning Section:
    • These settings are all the same as the photoshop HDR toning dialog for "Local Adaptation"
    • To preview what your toning settings will look like you can select any file(s) in your sequence by clicking "Select File(s)..." under "Preview". The file(s) you select will open and merge (if more than one file). When that's finished you can click the "Update Preview" button to apply the current toning settings and see what they will look like (I can't do the fast, automatic previews like the builtin dialog, sorry - somebody from adobe want to show me how to do this?)
    • You can see what the settings will look like at another point in your sequence by clicking the "Select File(s).." button again. (I recommend previewing a shot near the beginning, middle, and end of your sequence)
    • The dialog prevents you from using anything in photoshop while its open so I provided a zoom to allow you to zoom in on the preview
    • The tone curve you must enter as a comma separated list of points (sorry, ScriptUI is not really adequate to create the graphical histogram overlay for the curves like in the builtin dialog). The points are grouped into x,y pairs so for example: x1,y1,x2,y2,etc. Typically you will start with 0,0 and end with 255,255 (note that 255 is the max, full white). Like the curves tool, x represents the input and y represents the output
  • Output Section:
    • Click browse and select a folder for the script to save the output files to
    • The rest of this section should be self explanitory. NOTE: If you select to output 32bit files, the toning will not be applied, the files will simply be merged into a 32bit HDR image and saved.
  • Once you have specified the input and output folders the OK button should be enabled, when you are ready, click OK to start the process
  • Go watch a movie or take a nap, this is going to take a while. The script will display a progress window showing you how far along the proces is (the photoshop progress windows may occasionally appear on top of it, I usually just move them up a little so I can see both)

Limitations:

  • Only the local adaptation method is supported. It's really the only one I ever use, and I didn't really feel like implementing the other ones, but feel free to modify the script yourself to add this support
  • You canot load or save presets from the builtin toning dialog. The format of the preset files is binary and would require reverse engineering of the format and it would be very difficult to read to the files in javascript anyway. If it were xml, it would be much easier, alas it is not. Feel free to grab a hex editor and do this yourself. For now you'll just have to copy all of the values of a preset by hand into the dialog if you want to use a preset. If I have more time this is something I might work on.
  • Preview is slow because it has to do the actual full toning, I don't know a way to do the fast real time previews like the builtin dialog.
  • I don't think the "Cancel" button on the progress window really works, once running, the script is too busy to register a click, anybody know how I might fix this?
  • There may potentially be some ways to improve performance of this script in certain scenarios, IDK, but I'm just glad it works

You're welcome Adobe, you can send me a check at:

[REDACTED]

[REDACTED]

[REDACTED]

Please hit me up with comments/suggestions,

David

This topic has been closed for replies.

31 replies

Participating Frequently
February 4, 2017

I got it to work but i do have an issue with workspace vs Camera Raw.

When i manually use the photoshop merge to hdr i have no issues and i create the merge as a 32 bit before editing in ACR

But when i use your script to create any of the 32 bit versions my workspace is completely different vs Camera RAW version.  What variable in the script would be cause this as seen by my images below.

I tried all file version in your GUI and tried all 3 different options when opening in PS.  I see that your script is creating the file as a ProPhoto RBG instead of using the photos embeded SRGB.  Is there a way to create the hdr using embeded profile instead of the ProPhoto which is most likely the issue.  And yes, i have tried all 3 different ways to import from using your embeded phophoto to converting to working color space with no changes to the behavior.

ACR view

Workspace view

JJMack
Community Expert
Community Expert
February 4, 2017

Flash_Ghost wrote:

I got it to work but i do have an issue with workspace vs Camera Raw.

When i manually use the photoshop merge to hdr i have no issues and i create the merge as a 32 bit before editing in ACR

But when i use your script to create any of the 32 bit versions my workspace is completely different vs Camera RAW version. What variable in the script would be cause this as seen by my images below.

I tried all file version in your GUI and tried all 3 different options when opening in PS. I see that your script is creating the file as a ProPhoto RBG instead of using the photos embeded SRGB. Is there a way to create the hdr using embeded profile instead of the ProPhoto which is most likely the issue.

If the source image files in your folder are RAW files they have no color space.  They are not RGB image files its image is a mosaic of RAW sensor data.  Photoshop ACR Plug-in can convert the RAW data into an RGB image in any color space you desire in 8bit or 16bit color depth.  Which color space ACR will convert the RAW data into depends on the RAW file ACR settings.  If the RAW files have no ACR settings you current ACR Workflow options will be used.  What Are your current ACR Workflow settings?

JJMack
Participating Frequently
February 4, 2017

My ACR settings are set as follows.

If i were to open the RW2 file directly in PS i am presented with the ACR editor which i usually just hit the 'open object' button.  The image will look the exact same in the photoshop workspace as the ACR editor preview.  Same thing when using the merge to hdr in photoshop....everything matches up perfectly.

This is why  i feel you have logic in your script that is changing something along the way when merging the files.

Participating Frequently
February 2, 2017

Thank you for creating this amazing script.  I do have one issue with it and it is most likely due to my naming of the files.

I renamed my files from 1234.rw2 to 4_Cresent (1).rw2, (2).rw2 etc....

So when i run the batch it is grabbing them out of order and grabbing 1, 10, 100, 2, 20, 200 as my batch instead of 1,2,3,4,5,6.

Is there a line i can edit in the script to help me out...or is there a way i can rename all my files so that it will not happen.  I rename them right away when i am back in the office so i don't misplace them and can easily find the right file via a search if need be.

Thanks in advance.

Legend
February 2, 2017

It is the operating system and/or the general system settings which determine how numbers are treated in the sorting order.

Probably the easiest would be to rename the fields, so that a sufficient number of leading zeroes are in the name (such as "001", "002" etc. if the biggest ordinal number is less than 1000).

HTH.

kriss42910923
Participating Frequently
August 31, 2016

Hi, this sounds amazing and seems like it's wonderful for everyone!  I downloaded the latest file and I am running OSX 10.11.3 and Photoshop 2015.1.2 Release and it also says 20160113.r.355 x64.  I'm having a problem though when I run the script, I get this error.  Any ideas?  Thanks for the help!

Known Participant
June 6, 2018

Uhhh i'm having the same issue!  Did you manage to work this out?  I downloaded the jsx file, i tried copying the code into a fresh file, i've done all i could think off!  Either it doesn't show up in photoshop at all or it shows me that very error.  Been fighting with this for an hour, please help!

JJMack
Community Expert
Community Expert
June 7, 2018

Thank you - i did this, got the script to run - but i'm still getting that same error: "No such element.  Check number of files in source folder".  Any other ideas?


Did you check the number of files and the files in the source folder?  It look Like the Script tried to do  HDRToning with the some active document but there was a problem that the script caught.  The error was "No such Element"  Alerted you to the error that happened.  Looks like some element was missing in the current document.  The script suggest that you check the source folder files are correct.  I doe not create HDR images so I have no idea of what should be in the files in the source folder.

The doHDRToning function  Seems toe call  Adobe Automate  Merge to HDR Pro  plug-in script.

JJMack
bobafett2
Participating Frequently
May 11, 2016

After spending a LOT of money on photog equip and software lately, this was a great answer to SNS HDR Pro, (especially for free). I've been interested in HDR timelapses, and this script (after a short 120 shot test) worked perfectly. Love the presets you have built into it, (or, did it import mine??) Great job, and THANK YOU!!!!!

alex.furer
Known Participant
February 23, 2016

David, Thank you so very much for doing the work! This is a really awesome script. After assembling about 10 series of HDRs for panoramas I finally searched for an automated way to do this. I really think Adobe should buy you out and implement this script in Photoshop! Besides that, they should implement a way to fix chromatic aberrations to the entire HDR Pro import/creation process...

I also wanted to confirm that it works well on Win7 and Photoshop CC2015 (2016 update installed)

Nevertheless I noticed three things:

1) I loaded a adjustment profile that is not stored in the Photoshop folder but remains with the files in case I loose my OS partition. When I load it, the settings are correctly applied, but the loaded setting is not added to the drop-down list in the UI of your script. It is added if you run the "Merge to HDR Pro" manually. If I place the adjustment files in the appropriate folder inside the Photoshop installation, everything works as expected though.

2) I always shoot RAW and JPG. I tried to separate them using the "File Filter" in the UI of your script. I entered .CR2 in the "File Filter" slot. But after starting the script by pressing "OK", nothing happened. I got back to Photoshop and the script didn't run. (I attached a screenshot of my settings to this post below.)

Is there a way to see a log so I could try to debug what's happening?

My workaround the was to create a folder called "JPG" and move all the JPGs in there. After that the script ran as expected but showed 25 items instead of 24 (8 shots with each 3 brackets).

3) When you assemble a series of different shoots, the browse for input files and the browse for output files doesn't open the last directory that was opened. I noticed that on several Photoshop open dialogs, so I guess it's a Photoshop limitation. It can be quite tedious to always go through the entire process of finding the directory when you have to assemble many different HDR shots.

Is there a way to implement that in the script so it remembers the last directory?

I am not expecting you to honor my input and put more work into the script as it works perfectly. I merely post this here to contribute my experience, in case someone else runs into similar issues. Plus, the more we talk in this thread, the likelier Adobe will hear us and send you a check

Thanks!

Alex

Participant
May 2, 2016

It is failing with Photoshop CS6 and windows 10 x64.

Error 60: Not well-formed (invalid token).

Line: 757

-> <td id="LC74" class="blob-code blob-code-inner js-file-line">{</td>

Participant
January 6, 2016

This script is awesome. It worked first time on my 3786-image folder of 3-bracket pictures taken for a whole-day HDR time lapse. See it here: https://www.facebook.com/groups/689237787824303/permalink/937015926379820/

My environment is a Dell XPS 15 Laptop, Windows 8.1, 16GB, 1TB SSD, Photoshop CS6. It took abut 9.5 hours to run.

peters85418051
Participating Frequently
December 20, 2015

I see lots of Mac users, but has anybody tried this script in Windows?

marcelm____
Participant
January 31, 2016

Works fine on Win7 with PS CC2015(2016 Update installed)

Participant
August 14, 2015

This is amazing, thank you!

Probably a stupid question, but when I open the script in adobe CC 2015 the dialogue isn't large enough to fit all of the options (some are lost off the bottom of the page). I can't seem to change the output file. The lowest part visible is the "filename format" text field and I unfortunately cant change it from jpg. Hoping to edit the 32bit tiffs...

Any suggestions welcome, this is exactly what I was looking for! So close yet so far.


Thanks,

Matt


Participant
August 23, 2015

I've tried running this with PS CC 2014 and get this error:

Since that didn't work, I copied the code directly from git hub, pasted it into a blank txt doc, changed the extension to .jsx, saved it then copied it to the the scripts folder. After relaunching PS CC 2014, it didn't show up in the scripts menu. After that I attempted to debug using Extendscript toolkit. When launching, it defaulted to PS CS6, which I changed to CC 2014. Upon attempting to play the action in Extendscript it returned this:

I tried changing "# target photoshop" to "# target photoshop CC" and other variations to no avail. When I viewed the original code from the Batch HDR.jsx file from git hub in extenscript and text edit, it isn't the same as what you can preview on github. There's 3000+ lines of code with lots of "blob- code" throughout. I'm clearly missing something here. Although I'm not a developer, I've had success modifying and working with PS scripts in the past, but not this one.

d_13Author
Participating Frequently
August 23, 2015

You have downloaded and are trying to run the HTML page generated by github, rather than the script itself (the script is about 850 lines, so if you have 3000, that is definitely wrong). Try this link: https://github.com/davidmilligan/PhotoshopBatchHDR/raw/master/Batch%20HDR.jsx or you can checkout the code directly with git: Set Up Git - User Documentation

bluefantail
Participant
June 25, 2015

Hey there, I'm having the same issue as others above with "Error: No such element, Check number of files in source folder".

I've been through and checked the number of files (150, 5 shot brackets), checked for any hidden files, set a filter (*.ARW), and none of this has seemed to help. At the start it correctly identifies there's 150images starts loading the first 5 images, aligns them, and then when attempting to do the merge (or somewhere around there) it comes up with the error. Has anyone had any luck figuring out any other causes for it?

Weird thing was is it was working for a while, just stopped a couple of days ago.

Thanks

Participant
February 18, 2015

d@v!dm

It would be so so so amazing if this script worked for me. But I am getting the same error as a few people in this thread: "Error: No such element, Check number of files in source folder"

I have 420 images in my folder. My "Number of Brackets" is set to 3. 420 divided by 3 is 140 – an even number.

So i'm curious why this script is behaving as if I have an indivisible number of images in my folder?

I tried the "File Filter" field, but couldn't get it to work. admiralaelove said it helped his issue when he had the same error. But not sure why.

If anyone has a clue I would be very grateful. This script is so very helpful. If only it worked for me!

Thanks,


Matt

Participant
February 18, 2015
Participant
February 18, 2015

For some reason it says I have 421 images. If I go to the folder in the finder and "select all" it says I have 420 images in the folder.