Photoshop script - 2 sequence images auto align

New Here ,
May 17, 2016 May 17, 2016

Copy link to clipboard

Copied

Hello everyone,

I am new in this forum and just started learning about scripting in Photoshop. However, this specific task is beyond my limited knowledge.

We scanned an old film shot with 2 cameras (one recording the red colors and the other the green colors). The resulting output is one folder with an image sequence for the red (001.tff-999.tiff) and another folder with the same image sequence for the green (001.tiff-999.tiff).

I would need to generate a script (since doing it via actions is impossible) like this:

- Open file 001.tiff from one folder and 001.tiff from the other.

- Combine the 2 in one file via 2 layers.

- Auto align the 2 layers

- Save in a new folder.

- Repeat the process with the whole image sequence.

I would appreciate a lot your help. Thanks for sharing!

Regards,

Javier

TOPICS
Actions and scripting

Views

1.3K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
May 18, 2016 May 18, 2016

Copy link to clipboard

Copied

Can the image be aligned manually now?  They were shot with different cameras  from different locations.  Was there any special setup used to sync the taking of the images  at the same distance and same focal length.  Was the subject moving.   It is highly unlikely that image taken with different cameras can be aligned if the were not taken with that in mind using some specialized  setup. Perhaps have some reference and alignment points in the captured images.

Do the negatives you scanned align?

JJMack

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2016 May 18, 2016

Copy link to clipboard

Copied

Hi,

yes. The images can be aligned manually. The fact is, this film was shot with one camera with 2 film rolls. The camera had 2 prisms, dividing the red light and green light, the first being recorded in a panchromatic negative stock and the later in an orthocrhromatic stock. It was a process related to Technicolor. So, the answer is affirmative. I can auto-align the 2 images. But since the film roll has thousands of frames, I would need some sort of script to automate the process. Any clues?

Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
May 19, 2016 May 19, 2016

Copy link to clipboard

Copied

The next test you need to make is to see if Photoshop Autoalign layers will work on the two images stacked. If the can it should be quite easy to script the process.

Here I took and image layer duped it increased the canvas size lowered the opacity of the top layer and miss aligned the two layer.  I used an action to target the visible layers  and used Auto align layers to align the back. I use and action for auto align layers has a dialog that is not displayed when the action is played.  You will also need to use scriptlistener code for autoalign layers in you script for there is no DOM interface for it.

I wrote a script for someone recently that processes pairs of files the files were in a single folder and the names sorted the file so the front and back images were next to each other.   You could write a script like it the used one or two input folders and a single output folder.  You would also save out PSD file not jpeg files.  You would most likely open the first  convert to a normal layer, expand the canvas some place in the second, rasterize the placed layer, target both layer and auto align layers.

Capture.jpg

The script I wrote to help someone process pairs  of images.

#target photoshop

var savedRuler= app.preferences.rulerUnits; // Save Units

var orig_display_dialogs = app.displayDialogs; // Save dialog setting

app.preferences.rulerUnits = Units.PIXELS; // Work with pixels

app.displayDialogs = DialogModes.NO; // Set Dialogs off

var defaultFolder = "~"; // Default to desktop

var inputFolder = Folder.selectDialog("Choose a folder of images to process.", defaultFolder);

var outputFolder = Folder.selectDialog("Choose a folder to export resized images to.", defaultFolder);

var fileList = inputFolder.getFiles(/\.(nef|cr2|crw|dcs|raf|arw|orf|dng|jpg|jpe|jpeg|tif|tiff|psd|eps|png|bmp)$/i);

if (fileList.length%2===0) { // even number of files

  for (var i = 0; i < fileList.length; i++) { // Loop through files

     app.open(fileList); // Open First of Pair

     app.activeDocument.trim(TrimType.TOPLEFT); // Trim

     app.activeDocument.resizeImage(null,null,1200,ResampleMethod.NONE); // Resolution 1200

     var h = app.activeDocument.height; // Height

     var w = app.activeDocument.width; // Width

     i++; // Next File

     app.open(fileList); // open second of Pair

     app.activeDocument.trim(TrimType.TOPLEFT); // Trim

     app.activeDocument.resizeImage(null,null,1200,ResampleMethod.NONE); // Resolution 1200

     var h1 = app.activeDocument.height; // Height

     var w1 = app.activeDocument.width; // Width

     var maxDim = Math.max (Math.max (w, w1), Math.max (h, h1)) +10; // max side plus border

     app.activeDocument.resizeCanvas (maxDim, maxDim, AnchorPosition.MIDDLECENTER); // resize

     if (app.activeDocument.name.lastIndexOf(".")!=0 ) { var Name = app.activeDocument.name.substring(0, app.activeDocument.name.lastIndexOf(".")); }

     else {var Name =  app.activeDocument.name;} // Document Name

     var saveFile = outputFolder + "/" + Name ; // Output Path and File Name

     SaveAsJPEG(saveFile, 10); // save second and close

     activeDocument.close(SaveOptions.DONOTSAVECHANGES);     // Close the just save

     app.activeDocument.resizeCanvas (maxDim, maxDim, AnchorPosition.MIDDLECENTER); // resize

     if (app.activeDocument.name.lastIndexOf(".")!=0 ) { var Name = app.activeDocument.name.substring(0, app.activeDocument.name.lastIndexOf(".")); }

     else {var Name =  app.activeDocument.name;} // Document Name

     var saveFile = outputFolder + "/" + Name ; // Output Path and File Name

     SaveAsJPEG(saveFile, 10); // save and close First

     activeDocument.close(SaveOptions.DONOTSAVECHANGES);     // Close the just save

  } // loop ends

} // Even number ends

else { alert("Odd Number of Files");} // need to be an even number of Files

app.displayDialogs = orig_display_dialogs; // Restore display dialogs

app.preferences.rulerUnits = savedRuler; // Restore units

////////////////////////////////////////////////////////////////////////////////////////////////////////

function SaveAsJPEG(saveFile, jpegQuality){

  var doc = activeDocument;

  if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;

  jpgSaveOptions = new JPEGSaveOptions();

  jpgSaveOptions.embedColorProfile = true;

  jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

  jpgSaveOptions.matte = MatteType.NONE;

  jpgSaveOptions.quality = jpegQuality;

  activeDocument.saveAs(File(saveFile+".jpg"), jpgSaveOptions, true,Extension.LOWERCASE);

}

JJMack

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2016 May 20, 2016

Copy link to clipboard

Copied

Hi all,

I do not know if the following code can help, but the problem is very interesting (vintage effect).

// M'AC Finder ou WINDOWS Explorer, enables double click, Photoshop is opened and gets the focus

#target photoshop

app.bringToFront();

var unitRuler = app.preferences.rulerUnits;

var unitType = app.preferences.typeUnits;

main()

function main()

{

    alert('You must create the folder where combined images must be saved.');

    tiffSaveOptions = new TiffSaveOptions();  

    tiffSaveOptions.embedColorProfile = true;  

    tiffSaveOptions.alphaChannels = true; 

    tiffSaveOptions.annotations = true;    

    tiffSaveOptions.layers = true; 

    tiffSaveOptions.interleaveChannels = true;

    tiffSaveOptions.imageCompression = TIFFEncoding.NONE; 

    tiffSaveOptions.jpegQuality=12; 

    // skips alert messages in the process

    app.displayDialogs = DialogModes.NO;

     

    try

    {

        var greenFolder = Folder.selectDialog("Select the green images folder : ");

        var redFolder = Folder.selectDialog("Select the red images folder : ");

        var saveFolder = Folder.selectDialog("Select the destination folder : ");

        var greenFiles = greenFolder.getFiles(/\.(tif|tiff|)$/i);

        var redFiles = redFolder.getFiles(/\.(tif|tiff|)$/i);

        if (greenFiles.length!=redFiles.length)

        {

            alert('Error : numbers of green and red images are different.');

        }

        for (i=0;i<redFiles.length;i++)

        {

            var docRefRed = redFiles;

            var docRefGreen = greenFiles;

            if (docRefGreen.name!=docRefRed.name)

            {

                alert('Error : image names in green and red folders are different.');

            }

            open(docRefRed);

            open(docRefGreen);

            app.activeDocument = app.documents[0];

            app.activeDocument.selection.selectAll();

            app.activeDocument.selection.copy();

            app.activeDocument = app.documents[1];

            app.activeDocument.paste();

            mergeLayers();

            app.activeDocument.flatten();

            var saveFile = File(saveFolder + '/' + activeDocument.name);

            activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);

            while (app.documents.length > 0)

            { 

                app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

            }

        }

        app.preferences.rulerUnits = unitRuler;

        app.preferences.typeUnits = unitType;

    }

    catch(Error)

    {

        // A fatal error occurred

        alert(Error.description);

    }

   

    function mergeLayers()

    {

        var idsetd = charIDToTypeID( "setd" );

            var desc12 = new ActionDescriptor();

            var idnull = charIDToTypeID( "null" );

                var ref1 = new ActionReference();

                var idLyr = charIDToTypeID( "Lyr " );

                var idOrdn = charIDToTypeID( "Ordn" );

                var idTrgt = charIDToTypeID( "Trgt" );

                ref1.putEnumerated( idLyr, idOrdn, idTrgt );

            desc12.putReference( idnull, ref1 );

            var idT = charIDToTypeID( "T   " );

                var desc13 = new ActionDescriptor();

                var idMd = charIDToTypeID( "Md  " );

                var idBlnM = charIDToTypeID( "BlnM" );

                var idMltp = charIDToTypeID( "Mltp" );

                desc13.putEnumerated( idMd, idBlnM, idMltp );

            var idLyr = charIDToTypeID( "Lyr " );

            desc12.putObject( idT, idLyr, desc13 );

        executeAction( idsetd, desc12, DialogModes.NO );

    }

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 20, 2016 May 20, 2016

Copy link to clipboard

Copied

The OP wants to align the layers not merge them.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2016 May 20, 2016

Copy link to clipboard

Copied

Thanks, SuperMerlin, but if there is only one camera and 2 prisms (like in Pentax stéréo), why align images.

I think I did not understand the OP because of my English. Sorry.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 20, 2016 May 20, 2016

Copy link to clipboard

Copied

There will be a very slight difference.

This should align them.

#target photoshop;

app.bringToFront();

main();

function main(){

var firstFolder = Folder.selectDialog("Please select first folder");   

if(firstFolder == null ) return;

var PictureFiles = firstFolder.getFiles(/\.(tif|tiff)$/i);

var secondFolder = Folder.selectDialog("Please select second folder");   

if(secondFolder == null ) return;

var outputFolder = Folder.selectDialog("Please select output folder");   

if(outputFolder == null ) return;

for(var f in PictureFiles){

var Name = PictureFiles.name.replace(/\.[^\.]+$/, '');

var saveFile = new File(outputFolder + '/' + Name + '.psd');

var sFiles =[];   

var secondFile = File(secondFolder + "/" + PictureFiles.name);

if(secondFile.exists) {

sFiles.push(PictureFiles);

sFiles.push(secondFile);

    }else{

        continue;

        }

stackFiles(sFiles);

selectAllLayers();

autoAlign();

//Un-comment the line below to auto blend.

//autoBlend();

savePSD(saveFile);

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    }

};

function savePSD(saveFile){

psdSaveOptions = new PhotoshopSaveOptions();

psdSaveOptions.embedColorProfile = true;

psdSaveOptions.alphaChannels = true; 

psdSaveOptions.layers = true; 

activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);

};

function stackFiles(sFiles){ 

var loadLayersFromScript = true; 

var SCRIPTS_FOLDER =  decodeURI(app.path + '/' + localize('$$$/ScriptingSupport/InstalledScripts=Presets/Scripts'));

$.evalFile( new File(SCRIPTS_FOLDER +  '/Load Files into Stack.jsx'));  

loadLayers.intoStack(sFiles); 

};

function autoAlign() {

var desc = new ActionDescriptor();

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

desc.putReference( charIDToTypeID('null'), ref );

desc.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('ADSt'), stringIDToTypeID('ADSContent') );

desc.putEnumerated( charIDToTypeID('Aply'), stringIDToTypeID('projection'), charIDToTypeID('Auto') );

desc.putBoolean( stringIDToTypeID('vignette'), false );

desc.putBoolean( stringIDToTypeID('radialDistort'), false );

executeAction( charIDToTypeID('Algn'), desc, DialogModes.NO );

};

function autoBlend() {

var desc = new ActionDescriptor();

desc.putEnumerated( charIDToTypeID('Aply'), stringIDToTypeID('autoBlendType'), stringIDToTypeID('maxDOF') );

desc.putBoolean( charIDToTypeID('ClrC'), true );

executeAction( stringIDToTypeID('mergeAlignedLayers'), desc, DialogModes.NO );

};

function selectAllLayers() {

var desc = new ActionDescriptor();

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

desc.putReference( charIDToTypeID('null'), ref );

executeAction( stringIDToTypeID('selectAllLayers'), desc, DialogModes.NO );

};

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

Hello @SuperMerlin 

 

Your javascript seems like exactly what I need.  I can't get past this error:

auto_align_script_error.JPG

I tried placing .tiff files in the input folder.  I aslo tried changing the script to look for the file format I'm using .jpg.

 

var PictureFiles = firstFolder.getFiles(/\.(jpg|jpeg)$/i);

 

I have shots comprised of jpg image sequences.  I'm processing the shots.  When I process them, position and scale for a portion of the image is offset.  I'm trying to use your script to perspective auto align the processed image to match the original image.

 

So I believe I need a script to:

1.  Load original image into layer 1.

2.  Load processed image into layer 2.

3.  Designate the original image on layer 1 as the reference, so that the processed image on layer 2 is perpective transformed to match the original image on layer 1.

4.  Auto-align layer 2 to layer 1.

5.  Export the aligned layers, with layer 2 on top, to an uncompressed file (not .psd).

6.  Repeat script on each matched pair until all pairs in the folders are procesed.

 

I also assume that in your script:

"Folder 1" = original files (contains the first set of matched pairs identically named as their match in folder 2).

"Folder 2" = processed files (contains the other set of matched pairs identically named as their match in folder 1).

"Output Folder" = photoshop aligned exported file.

 

Here is a link to two test files, in the folders I used to test the script:

https://drive.google.com/drive/folders/1JUFOsGf3zH0gg2etAmEnijjKvNdxPJy1?usp=sharing

 

FYI - The processed image is only the portion of the frame that has been position and scale offset by the processing.  So the result I'm looking for is exactly what photoshop does when you manually auto-align the two uploaded images.  I don't want the processed image to be auto-aligned to full frame, just aligned against the portion of the original image that came from.

 

Totally willing to pay for your time for a solution.  We can DM or Discord, or something.

 

Thanks!

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
May 20, 2016 May 20, 2016

Copy link to clipboard

Copied

Yes I know I outline a way to do that and he would save out a layered psd. After aligning the two layers.  I did not write the codef for him Posted what I did as a guide as to how to proocess pairs of images.

JJMack

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 21, 2016 May 21, 2016

Copy link to clipboard

Copied

Dear all,

thank you for all the posts. This forum is awesome.

Please allow me to be more precise about the project and the script.

We have 2 old negative film rolls shot with a camera using a primitive system of Technicolor. As I said, one roll captured the "red" colors while the other captured the "green" colors. Both film rolls are on black and white stock (one panchromatic, the other orthochromatic).

We are planning to scan the film rolls at 4K or 6K resolution using a motion picture scanner. After that, it's when things get interesting...and complicated.

As I said, the idea of the script is to load scan "green" 01.dpx and load scan "red" dpx into a file (in different layers). Perform the auto-align, then I was thinking to load an action because I need to composite the files to obtain the color. After, I would flatten the image and obtain the final "colored" file as .dpx.

This is the idea. It's a very interesting project but quite complex, specially with my limited knowledge of scripting. But, I'm learning a lot in this forum.

Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

Edit: Oops, wrong topic!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

Hello, @Stephen_A_Marsh,

 

Thanks for the email regarding the imageprocessing plug in that should do what's described above.  How are you now installing plug ins that are not in the adobe market place?  I attempted with this script, failed:

 

Adobe discontinued Adobe Extensions Manager, and I can't find a way to use the Creative Cloud Desktop app because it seems to only allow you to download and install plugins from the marketplace.


They give you the options to use a command prompt:


https://helpx.adobe.com/creative-cloud/kb/installingextensionsandaddons.html#Installpluginsorextensi...

 

Tried installing this with Adobe command prompt, but it failed.

C:\WINDOWS\system32>cd C:\Users\WB_PC\Desktop\Installs\Installers_Manuals\ExManCmd_win

C:\Users\WB_PC\Desktop\Installs\Installers_Manuals\ExManCmd_win>ExManCmd.exe /ImageProcessorPro-3_2b5.zxp
Unknown option specified: ImageProcessorPro-3_2b5.zxp

C:\Users\WB_PC\Desktop\Installs\Installers_Manuals\ExManCmd_win>ExManCmd.exe/ImageProcessorPro-3_2b5.zxpp
Unknown option specified: ImageProcessorPro-3_2b5.zxpp

How do you install this now?
Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

@Stephen_A_Marsh nevermind, I see the error, long day.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

LATEST

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines