Skip to main content
Participant
May 18, 2016
Question

Photoshop script - 2 sequence images auto align

  • May 18, 2016
  • 4 replies
  • 2859 views

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

This topic has been closed for replies.

4 replies

Stephen Marsh
Community Expert
Community Expert
April 21, 2021

Edit: Oops, wrong topic!

Known Participant
April 22, 2021

Hello, @Stephen 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:


Install plugins or extensions using the Creative Cloud desktop app

 

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!

Known Participant
April 22, 2021

@Stephen Marsh nevermind, I see the error, long day.

Participant
May 21, 2016

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!

JJMack
Community Expert
Community Expert
May 19, 2016

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.

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
MR74270
Inspiring
May 20, 2016

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

    }

}

SuperMerlin
Inspiring
May 20, 2016

The OP wants to align the layers not merge them.

JJMack
Community Expert
Community Expert
May 18, 2016

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
Participant
May 19, 2016

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!