I have created a Photoshop Script (using JavaScript) for batch creation of HDR images.
I have used these previous discussions during implementation.
In the beginning part of the script there are some options that you can change to customize the script's operation.
You are free to modify this script and publish your modifications.
The script can be found at the following URL (which is a git repository in itself) , and is also pasted below.
https://gist.github.com/1640233
// Batch Creation of HDR files
// -----------------------------------------------------------------------------------
// Opens a dialog box, asking for the container folder.
// The container folder must have separate sub folders for each of the HDR image series
// The output can be saved in a subfolder with an arbitrary name by
// changing the options below.
//
// example: to save hdr files as
// C:\container\hdrseries1\myhdrfolder\myhdr.psd
// change the options HDROutputFolder to "myhdrfolder"
// and option HDRFileName to "myhdr"
//
// Extensions of source image files
var pictureExtensions = "*.jpg";
// Sub-folder to save the resulting HDR file. This folder will be created if it does not exist.
//var HDROutputFolder = ""; // disable subfolder like this
var HDROutputFolder = "HDR"
// Filename for saved HDR file. Do not set the extension here, extension is set automatically according to saveResultAsEXR option.
var HDRFileName = "HDR";
// Save EXR file (requires EXR plugin) If set to "false" saves the HDR as a .PSD file
var saveResultAsEXR = false;
// Overwrite existing HDR output files? If set to "false" skips creating HDR files for already created image sets.
// This is useful for adding some new HDR sets into the container folder, and running the script again
// to crate HDR files only for the newly added series.
var overwriteExistingHDR = false;
// --------------- End of settings ------------------- //
var runMergeToHDRFromScript = true;// define and set to true before including Merge To HDR.jsx
var g_ScriptFolderPath = app.path + "/"+ localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts");
var g_ScriptPath = File( g_ScriptFolderPath+'/Merge To HDR.jsx' );
$.evalFile( g_ScriptPath );
// function to manually save an EXR file. Requires EXR plugn to be installed
function saveEXR(saveFile){
var idsave = charIDToTypeID( "save" );
var desc6 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
desc6.putString( idAs, "OpenEXR" );
var idIn = charIDToTypeID( "In " );
desc6.putPath( idIn, saveFile );
executeAction( idsave, desc6, DialogModes.NO );
}
function main()
{
var bracket_folders = [];
var selected_folder = Folder.selectDialog ("Select the container folder. The container folder should have a separate folder inside for each HDR image series.")
if (selected_folder != null)
{
// to process multiple container folders, uncomment following line and edit folder paths.
//bracket_folders = [ Folder('/c/images/bracket5'), Folder('/c/images/bracket9')];
bracket_folders = bracket_folders.concat(selected_folder);
for (var f = 0; f < bracket_folders.length; f++)
{
var image_folders = bracket_folders[f].getFiles();
for (var g = 0; g < image_folders.length; g++)
{
var folder = image_folders[g];
var filelist = image_folders[g].getFiles(pictureExtensions);
var photoshopHDRFolder = Folder(folder.absoluteURI + "/" + HDROutputFolder);
if (saveResultAsEXR) {
var extension = ".exr";
} else {
var extension = ".psd";
}
var photoshopHDRFile = File(photoshopHDRFolder.absoluteURI + "/" + HDRFileName + extension);
if (overwriteExistingHDR ==false && photoshopHDRFile.exists == true) {
continue;
}
mergeToHDR.useAlignment = true;
mergeToHDR.outputBitDepth= 32;
mergeToHDR.mergeFilesToHDR( filelist, true, -2 );
if (photoshopHDRFolder.exists == false) {
photoshopHDRFolder.create();
}
if (saveResultAsEXR) {
saveEXR(photoshopHDRFile);
} else {
activeDocument.saveAs(photoshopHDRFile ); // Use for PSD files
}
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
}
main();
You have to organize your files inside folders like this.
main_container
|
`-> hdr1
| `-> 0.jpg , 1.jpg 2.jpg ....
`-> hdr2
`-> 0.jpg , 1.jpg 2.jpg ....
And your main_container folder must only include folders. It should not contain single files. That may be your problem.
You can debug it by putting alert(image_folders[g])
just below the problematic line;
var filelist = image_folders[g].getFiles(pictureExtensions);
Probably you hava a file in main_container, and the alert will give you its name.
I agree the reason for the error is most likely bracket_folders[f] is not a Folder. I think a better fix would be to change
var image_folders = bracket_folders[f].getFiles();
to
if( image_folders[g] instanceof Folder) continue;// only process folders
var image_folders = bracket_folders[f].getFiles();
Good idea,
I cannot edit my first post, but I have updated the gist:
https://gist.github.com/1722968
download the file directly from here.
Nice work. Very nice.
I have just completed a script that identifies bracketed sets from a within a folder.
The script you have written is a great next step to automate the HDR production process.
I have taken the time to calibrate the response curve of my camera sensor.
Is there a setting in the mergeToHDR API that lets a predefined response curve to be specified for the HDR creation process?
I'm using CS5.
From looking at the script it seems to me that you might be able to skip the dialog and still use your responce curve preset. The script has a line..
const kMergeToHDRUIResponseCurve = app.charIDToTypeID( 'EmCV' );
You just need to know what charID or stringID to use to replace the defaut. You should be able to find that ID by running the script with the dialog and pulling apart the descriptor.
I spent a few hours reverse engineering the HDR Pro script in Photoshop.
The bad news is that the response curve can't be specified.
The code I refer to just loads a list of the available response curves (the ones previously saved in Photoshop's defulat directory) and passes it to the HDR merging module.
Now that I have customised an HDR stacker script to handle long exposures, I am wondering why the "Process Collections" command doesn't work on the results.
My script creates groups of images that correspond to an HDR set, just like Adobe's script.
However "Process Collections" doesn't seem to recognise the groupings. Is there some metadata values that is set by the adobe stacker script?
Hi,
I've been using your script quite successfully for some time (Thanks for it btw !), but it crashes from time to time. Mainly, it gives me an error that the images can not be aligned properly, or even worse, it's not saving the image and the script errors.
Apparently, all the errors are coming from the Merge To HDR.jsx script, but if I'm launching the HDR merge by hand from bridge on the erroring images, it's working fine ...
So I'm wondering if it would be some parameters that would need to be re-initialized or something else in order to get it work properly in the batch.
Let me know if you have any idea why it would error like that.
Thanks a lot,
Julien
Hi Julien,
I'm not sure about the cause of the errors. I would recommend inspecting the "Merge To HDR.jsx" script itself to find out any parameters about alignment process, it has a very limited documentation and internet searches are not much helpful.
Have you double checked the directory structure and made sure that similar image sequences are not intermixed ?
Hi everyone,
i try to run this script, also in the scripteditor with photoshop cs5,1 64 bit toolkit, but it doesnt work.
after the first hdr merge it crashs and says that it can not achieve the function "main".
it just create a empty folder in der first one.
any idea? how can i solve the problem.
thanks a lot,
uhu
I picked this script up this morning, using it to merge exposures for panoramas. Couple of things I found; first was the check for directories mentioned earlier, I dropped in a check for that. The second was that the merged images were coming out looking horribly flat in the skies. It took me a while to work out that it was the third argument to the mergeToHDR.mergeFilesToHDR() method, ghosting. For now I've changed it to null, which is obviously not great but I thought it might be a useful pointer to someone having the same problem.
Finally, rather than 30 folders of 3 EV brackets each, I rejigged the code so that it looks in a single folder where the images are ordered EV1, EV2, EV3, EV1, EV2, EV3 and works it all out. It makes life quicker for me. If anyone's interested I'll post it here once I've tidied my horribly ugly code.
Big thanks to the contributors to this.
North America
Europe, Middle East and Africa
Asia Pacific