Skip navigation
Currently Being Moderated

Batch HDR creation script

Jan 19, 2012 6:28 AM

Tags: #batch #hdr #exr

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();
 
Replies
  • Currently Being Moderated
    Feb 1, 2012 4:42 PM   in reply to gokdenizkaradag

    Hi, this script looks great but it fails when I try and run it under both CS4 and CS5.1

     

    Cannot execute script in target engine 'main'!

    (#24) image_folders[g].getFiles is not a function

     

     

    I am running this under OSX.

     

    Any ideas?

     

    Thanks,

    Phil

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 2, 2012 1:41 AM   in reply to PhilSpitler

    If you are running this script from ExtendScript Toolkit make sure you select Photoshop from the top left hand dropdownlist.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 2, 2012 2:57 AM   in reply to PhilSpitler

    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();

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 3, 2012 6:58 PM   in reply to gokdenizkaradag

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 3, 2012 8:12 PM   in reply to karmadiI10

    Have looked at the code of the MergeToHDR Pro script.

    As far as I can tell the scripted process without a dialog allows Ghosting, Alignment, and source images to be specified only.

    This means it is necessary to use the interactive dialog to choose a response curve preset.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 4, 2012 10:21 AM   in reply to karmadiI10

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 13, 2012 2:49 PM   in reply to gokdenizkaradag

    Thank you for posting this script! I got the script to work, but I was wondering if there was script to write to make the HDR file have the Surrelistic effect.

     

    I am new to javascript and any help would be much appreciated!

     

     

    Thanks!

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 30, 2012 8:52 PM   in reply to karmadiI10

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 30, 2012 8:59 PM   in reply to gokdenizkaradag

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 24, 2012 3:48 AM   in reply to karmadiI10

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 2, 2012 12:01 PM   in reply to gokdenizkaradag

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 17, 2012 7:04 AM   in reply to byuhu

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)