2 Replies Latest reply on Jun 9, 2016 6:25 AM by saluther55

    Photoshop - combine purple and green channel images into a merged image?




      My molecular biology lab is attempting to batch merge images obtained from a Confocal Microscope.  The microscope uses lasers to view various parts of a sample within a number of channels.


      For each sample, there is two corresponding channels at each level.  We are attempting to merge all of these corresponding images into one combined image.  The process of merging images is straightforward; however, we need to do this 150-250 times for each sample and we have multiple samples.


      I found an old forum post (Photoshop - combine red and green channel images into a merged image? ) that involved writing a script for exactly this.  However, the script is not working for me.  I'm new to using scripts in photoshop and would greatly appreciate any possible help. 


      Here is the code, I've attempted to run.

      // make a reference to the savedFolder  
      var savedFolder = new Folder('~/desktop/Merged Image');  
      // create the folder if it doesn't exists  
      if(!savedFolder.exists) savedFolder.create();  
      // get the source folder from the user and store in variable  
      var sourceFolder = Folder.selectDialog();  
      // make sure user selected a folder  
      if(sourceFolder != null){  
          // get an array of red images and store in variable  
          var sourceFiles = sourceFolder.getFiles(/_ch00\.tif$/i);  
          // make a loop to process all found sets.  
          for(var i = 0; i < sourceFiles.length;i++){  
              var redName = sourceFiles[i].name;  
              var greenName = redName.replace('_ch00','_ch01');  
              var redImage = open(sourceFiles[i]);// open the red file and store reference to document  
              var greenImage = open(new File(sourceFolder+'/'+greenName));// open the green file and store reference that document  
              // now apply redImge using lighten mode  
              applyChannel( charIDToTypeID( "RGB " ) , redImage.name );  
              // save the merged document  
              // close the open documents for next loop  
      function applyChannel( channelID, documentName ){  
          // charIDToTypeID( "RGB " )  
          // charIDToTypeID( "Rd  " )  
          // charIDToTypeID( "Grn " )  
          // charIDToTypeID( "Bl  " )  
          var desc = new ActionDescriptor();  
          var channelsDesc = new ActionDescriptor();  
          var ref = new ActionReference();  
          ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), channelID);  
          ref.putProperty( charIDToTypeID( "Lyr " ), charIDToTypeID( "Bckg" ) );  
          ref.putName( charIDToTypeID( "Dcmn" ), documentName );  
          channelsDesc.putReference( charIDToTypeID( "T   " ), ref );  
          channelsDesc.putEnumerated( charIDToTypeID( "Clcl" ), charIDToTypeID( "Clcn" ), charIDToTypeID( "Lghn" ) );  
          channelsDesc.putBoolean( charIDToTypeID( "PrsT" ), true );  
          desc.putObject( charIDToTypeID( "With" ), charIDToTypeID( "Clcl" ), channelsDesc );  
          executeAction( charIDToTypeID( "AppI" ), desc, DialogModes.NO );  
      function SaveAsTIFF( inFileName, inLZW ) {  
          var tiffSaveOptions = new TiffSaveOptions();  
          if ( inLZW ) {  
              tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;  
          } else {  
              tiffSaveOptions.imageCompression = TIFFEncoding.NONE;  
          app.activeDocument.saveAs( File( inFileName ), tiffSaveOptions );  


      Basically, all I changed from the original code was the "_r" to "_ch00" and "_g" to "_ch01".  Thinking that was the only difference between the original post and mine was the file names.  I ran the script in Adobe ExtendScript ToolKit.  The code is not able to get past line 15 without the error "open is not a function"


      I tried saving the script and trying it out in photoshop anyway and I get the error code "Error 8800: General Photoshop error occured. This functionality may not be available in this version of photoshop.  -The command 'Apply Image' is not currently available. Line 41 ->   executeAction( CharIDToTypeID('Appl'), desc, DialogModes.NO );"


      I honestly don't know enough about coding to even know where to begin troubleshooting this problem.  Any direction would be extremely appreciated!