Automating Photomerge to run folder-batches

Discussion of Automation, Image Workflow and Raw Image Workflow

Moderators: xbytor, DavideBarranca, Paul MR

CelticPixie

Automating Photomerge to run folder-batches

Post by CelticPixie » Tue Jul 14, 2009 2:18 pm

Hi,

I'm taking a lot of panoramic images, anything between 5 and 13 exposures. I found Photoshop's "Photomerge" function works best for stitching them together.

My workflow is to save the source files for each panorama inside a separate folder: For example "Pano1" contains 5 files, "Pano2" contains 7 files, "Pano3" contains 9 files.

Is there a way of automating/telling Photoshop to take all the images inside a folder and stitch/photomerge them together to a panorama, and then proceed to the next folder,... until all folders are processed.

I've got very basic knowledge of programming languages: I guess I'd understand the basics of what a script does & modify an exisiting script – but I couldn't code something myself.
Can someone here please help me?

Thanks a lot!
CPixie

Mike Hale

Automating Photomerge to run folder-batches

Post by Mike Hale » Tue Jul 14, 2009 3:22 pm

This should be close to what you what.

Code: Select allvar runphotomergeFromScript = true; // must be before Photomerge include
//@includepath "/c/Program Files/Adobe/Adobe Photoshop CS4/Presets/Scripts/"
//@include "Photomerge.jsx"
//@show include

var workFolder = Folder.selectDialog();
var fList = workFolder.getFiles( '*.tif' );

// override Photomerge.jsx settings. Default is "Auto". Uncomment to override the default.
//photomerge.alignmentKey   = "Auto";
//photomerge.alignmentKey   = "Prsp";
//photomerge.alignmentKey   = "cylindrical";
//photomerge.alignmentKey   = "spherical";
//photomerge.alignmentKey   = "sceneCollage";
//photomerge.alignmentKey   = "translation"; // "Reposition" in layout dialog   

// other setting that may need to be changed. Defaults below
photomerge.advancedBlending      = true; // 'Bend Images Together' checkbox in dialog
photomerge.lensCorrection      = false; // Geometric Distortion Correction'checkbox in dialog
photomerge.removeVignette      = false; // 'Vignette Removal' checkbox in dialog

if( fList.length > 1 ){
   photomerge.createPanorama(fList,false);
}
// The merged doc will be the activeDocument

CelticPixie

Automating Photomerge to run folder-batches

Post by CelticPixie » Wed Jul 15, 2009 5:56 am

Hi Mike,

Thanks a lot for the script! I'm working in OSX, so I've tweaked the includepath a little.
I placed the script inside the same scripts folder as the Photomerge script, started up Photoshop and ran it from the File/Scripts menu.
It works fine – but only for the folder I specify in the beginning. Not for a whole batch of folders. I tried implementing your script into a 'normal' Photoshop action, then go "File/Automate/Batch..." and select "include subfolders", but it won't work that way.

Maybe I should explain my folder structure/workflow a bit better:

Panoramas/Pano1/File1.tif
Panoramas/Pano1/File2.tif
Panoramas/Pano1/File3.tif

Panoramas/Pano2/File1.tif
Panoramas/Pano2/File2.tif
Panoramas/Pano2/File3.tif
Panoramas/Pano2/File4.tif
Panoramas/Pano2/File5.tif

Panoramas/Pano3/File1.tif
Panoramas/Pano3/File2.tif
Panoramas/Pano3/File3.tif
Panoramas/Pano3/File4.tif

...and so on.

What I'd like to do is: Set/select the workfolder (in my example "Panoramas"), so that the script then automatically works it's way through the subfolders ("Pano1", "Pano2",...) and automatically merges all the files inside a subfolder to a panorama & then moves on to the next subfolder for a new panorama.

Ideally, the results/panoramas would be saved automatically (filename could be the same as the subfolder names, for example).

Thanks a lot for your time & input!
CPixie

Mike Hale

Automating Photomerge to run folder-batches

Post by Mike Hale » Wed Jul 15, 2009 3:41 pm

This should work with one level of folders. Note that I did not test it.

Code: Select allvar runphotomergeFromScript = true; // must be before Photomerge include
//@includepath "/c/Program Files/Adobe/Adobe Photoshop CS4/Presets/Scripts/"
//@include "Photomerge.jsx"
//@show include

psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;

var workFolder = Folder.selectDialog();
var folders = workFolder.getFiles( function( file ) { return file instanceof Folder; } );

for( var i = 0; i < folders.length; i++ ) {
   
   var fList = workFolder.getFiles( '*.tif' );

   // override Photomerge.jsx settings. Default is "Auto". Uncomment to override the default.
   //photomerge.alignmentKey   = "Auto";
   //photomerge.alignmentKey   = "Prsp";
   //photomerge.alignmentKey   = "cylindrical";
   //photomerge.alignmentKey   = "spherical";
   //photomerge.alignmentKey   = "sceneCollage";
   //photomerge.alignmentKey   = "translation"; // "Reposition" in layout dialog   

   // other setting that may need to be changed. Defaults below
   photomerge.advancedBlending      = true; // 'Bend Images Together' checkbox in dialog
   photomerge.lensCorrection      = false; // Geometric Distortion Correction'checkbox in dialog
   photomerge.removeVignette      = false; // 'Vignette Removal' checkbox in dialog

   if( fList.length > 1 ){
      photomerge.createPanorama(fList,false);
   }
   // The merged doc will be the activeDocument
   activeDocument.saveAs( new File( flist[0].parent + '/completed.psd' ) , psdOpts, true, Extension.LOWERCASE);
   activeDocument.close( SaveOptions.DONOTSAVECHANGES );
}

xbytor

Automating Photomerge to run folder-batches

Post by xbytor » Wed Jul 15, 2009 9:35 pm

Code: Select all var fList = workFolder.getFiles( '*.tif' );

should probably be

Code: Select all var folder = folders;
var fList = folder.getFiles( '*.tif' );


And, of course, I haven't tested either :)

-X

Mike Hale

Automating Photomerge to run folder-batches

Post by Mike Hale » Wed Jul 15, 2009 10:07 pm

Your right X. I forgot to change that when I put in the loop.

CelticPixie

Automating Photomerge to run folder-batches

Post by CelticPixie » Tue Jul 21, 2009 8:25 am

Thanks a lot guys - works a treat! The only thing that doesn't work is the file-saving. (Error 2: flist is undefined). But that's no problem, as I'll just run the panoramas in batches of 10 and then save them manually..

CPixie

xbytor

Automating Photomerge to run folder-batches

Post by xbytor » Tue Jul 21, 2009 12:31 pm

flist should probably be fList.

ccisystems

Automating Photomerge to run folder-batches

Post by ccisystems » Wed Sep 23, 2009 7:09 pm

Mike Hale wrote: // The merged doc will be the activeDocument
activeDocument.saveAs( new File( flist[0].parent + '/completed.psd' ) , psdOpts, true, Extension.LOWERCASE);
activeDocument.close( SaveOptions.DONOTSAVECHANGES );
}[/code]

This script is brilliant! One issue I have hit though, is if the panoramas are larger than what PSD supports, even if you specify '.psd' in the saveAs options, Photoshop stops the processing and asks for a file name for a .psb file. I know that's the file format for large documents but specifying .psb in the file saveAs does not help -- Photoshop still prompts for the file name and path. Not very helpful when wanting to let it run unattended. Does anyone have a clue why it does not just save like it does with psd? Much appreciated. I posted this question with example code I am using in the 'Help Me' forum but nobody seems to have an idea there.

Mike Hale

Automating Photomerge to run folder-batches

Post by Mike Hale » Wed Sep 23, 2009 9:36 pm

I did see your other post but I don't have an answer yet.

I'm facing a deadline on another project. If no one else has helped I'll try to find a fix when I can.

Post Reply