Macro Broken since updating to ImageJ 1.46m

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro Broken since updating to ImageJ 1.46m

andrewspracklen
I cobbled together the macro that appears below to allow me to batch convert zeiss lsm files into individual .tiff files for each channel. After some user input, it will also batch merge the specified channels into a single image. However, after recently updating both the FIJI distribution of ImageJ and ImageJ, this macro has been rendered broken. As best I can figure, it has something to do with setting it to run in batch mode. Any help/advice to get this macro up and running again would be great! Thank you in advance.

//will batch ssplit/merge image files using user defined parameters
//
//add: macro "Batch Split/Merge LSM Files"{
// runMacro("Batch merge LSM v2");
// }
//to startupmacros.txt
dir1 = getDirectory("Choose Source Directory");
list = getFileList(dir1);
dir2 = dir1+"Split"+File.separator;
dir3 = dir1+"Merge"+File.separator;
File.makeDirectory(dir2)
File.makeDirectory(dir3)
Dialog.create("How many channels?");
Dialog.addChoice("Channels:", newArray("2", "3", "4"));
Dialog.show();
channels = Dialog.getChoice;

if ((channels=="2")) {
splitmerge2();
}
else if ((channels=="3")) {
splitmerge3();
}
else if ((channels=="4")) {
splitmerge4();
}

function splitmerge2(){
for (i=0; i<list.length; i++)
        {

        if (File.isDirectory(dir1+list[i])){}
        else{

                        path = dir1+list[i];
                        if (endsWith(path, ".db")){}
                        else{

                                setBatchMode(true);
                                open(path);
                                if (bitDepth!=8){}
                                else {
                                               
                                                title = File.nameWithoutExtension ;
                                                run("Split Channels");
                                               
                                                //saveAs("Tiff", dir2+title+"c3.tif");
                                                //close();
                                                saveAs("Tiff", dir2+title+"c2.tif");
                                                close();
                                                saveAs("Tiff", dir2+title+"c1.tif");
                                                close();
                                                setBatchMode(false);

                                                }
                                        }
                                }
                        }
}

function splitmerge3(){
for (i=0; i<list.length; i++)
        {

        if (File.isDirectory(dir1+list[i])){}
        else{

                        path = dir1+list[i];
                        if (endsWith(path, ".db")){}
                        else{

                                setBatchMode(true);
                                open(path);
                                if (bitDepth!=8){}
                                else {
                                               
                                                title = File.nameWithoutExtension ;
                                                run("Split Channels");
                                               
                                                saveAs("Tiff", dir2+title+"c3.tif");
                                                close();
                                                saveAs("Tiff", dir2+title+"c2.tif");
                                                close();
                                                saveAs("Tiff", dir2+title+"c1.tif");
                                                close();
                                                setBatchMode(false);

                                                }
                                        }
                                }
                        }
}

function splitmerge4(){



for (i=0; i<list.length; i++)
        {

        if (File.isDirectory(dir1+list[i])){}
        else{

                        path = dir1+list[i];
                        if (endsWith(path, ".db")){}
                        else{

                                setBatchMode(true);
                                open(path);
                                if (bitDepth!=8){}
                                else {
                                               
                                                title = File.nameWithoutExtension ;
                                                run("Split Channels");
                                               
                                                saveAs("Tiff", dir2+title+"c4.tif");
                                                close();
                                                saveAs("Tiff", dir2+title+"c3.tif");
                                                close();
                                                saveAs("Tiff", dir2+title+"c2.tif");
                                                close();
                                                saveAs("Tiff", dir2+title+"c1.tif");
                                                close();
                                                setBatchMode(false);

                                                }
                                        }
                                }
                        }
}

Dialog.create("Batch Merge");
Dialog.addChoice("Channels:", newArray("2", "3", "4"));
Dialog.show();
channels = Dialog.getChoice;
        if (channels==2) {
                Dialog.create("Chanel Order");
                Dialog.addString("Blue:", "c1");
                Dialog.addString("Red:", "c2");
                Dialog.addCheckbox("Open as Stack", false);
                Dialog.show();
               
                blueSuffix = Dialog.getString() + ".";
                redSuffix = Dialog.getString() + ".";
                openAsStack = Dialog.getCheckbox();
                if (openAsStack)
                        openImagesAsStack2();
                else
                        batchConvert2();
                exit;
        }
        else if ((channels==3)) {
                Dialog.create("Chanel Order");
                Dialog.addString("Blue:", "c1");
                Dialog.addString("Green:", "c2");
                Dialog.addString("Red:", "c3");
                Dialog.addCheckbox("Open as Stack", false);
                Dialog.show();

                blueSuffix = Dialog.getString() + ".";
                greenSuffix = Dialog.getString() + ".";
                redSuffix = Dialog.getString() + ".";
                openAsStack = Dialog.getCheckbox();
                if (openAsStack)
                        openImagesAsStack();
                else
                        batchConvert();
                exit;
        }
        else if ((channels==4)) {
                Dialog.create("Chanel Order");
                Dialog.addString("Blue:", "c1");
                Dialog.addString("Green:", "c2");
                Dialog.addString("Red:", "c3");
                Dialog.addString("Far Red:", "c4");
                Dialog.addCheckbox("Open as Stack", false);
                Dialog.show();

                blueSuffix = Dialog.getString() + ".";
                greenSuffix = Dialog.getString() + ".";
                redSuffix = Dialog.getString() + ".";
                graySuffix = Dialog.getString() + ".";
                openAsStack = Dialog.getCheckbox();
                if (openAsStack)
                        openImagesAsStack4();
                else
                        batchConvert4();
                exit;
        }
        else if ((channels<=1)) {
                Dialog.create("ERROR");
                Dialog.addMessage("Number of channels must be 2, 3, or 4.");
                Dialog.show();
        }
        else if ((channels>=5)) {
                Dialog.create("ERROR");
                Dialog.addMessage("Number of channels must be 2, 3, or 4.");
                Dialog.show();
        }

function openImagesAsStack() {
      list = getFileList(dir2);
      setBatchMode(true);
      n = list.length;
      if ((n%3)!=0)
         exit("The number of files must be a multiple of 3");
      stack = 0;
      first = 0;
      for (i=0; i<n/3; i++) {
          showProgress(i+1, n/3);
          red="?"; green="?"; blue="?";
          for (j=first; j<first+3; j++) {
              if (indexOf(list[j], redSuffix)!=-1)
                  red = list[j];
              if (indexOf(list[j], greenSuffix)!=-1)
                  green = list[j];
              if (indexOf(list[j], blueSuffix)!=-1)
                  blue = list[j];
          }
          open(dir2+red);
          open(dir2+green);
          open(dir2+blue);
          run("Merge Channels...", "red=["+red+"] green=["+green+"] blue=["+blue+"] gray=*None* ");
          width=getWidth; height=getHeight;
          run("Copy");
          close();
          if (stack==0) {
              newImage("RGB Stack", "RGB Black", width, height, n/3);
              stack = getImageID;
          }
          selectImage(stack);
          setSlice(i+1);
          run("Paste");
          index = indexOf(red, redSuffix);
          name = substring(red, 0, index);
          setMetadata(name);
          first += 3;
      }
      setSlice(1);
      run("Select None");
      setBatchMode(false);
  }

function openImagesAsStack2() {
      list = getFileList(dir2);
      setBatchMode(true);
      n = list.length;
      if ((n%2)!=0)
         exit("The number of files must be a multiple of 2");
      stack = 0;
      first = 0;
      for (i=0; i<n/2; i++) {
          showProgress(i+1, n/2);
          red="?"; blue="?";
          for (j=first; j<first+2; j++) {
              if (indexOf(list[j], redSuffix)!=-1)
                  red = list[j];
              if (indexOf(list[j], blueSuffix)!=-1)
                  blue = list[j];
          }
          open(dir2+red);
          open(dir2+blue);
          run("Merge Channels...", "red=["+red+"] green=*None* blue=["+blue+"] gray=*None* ");
          width=getWidth; height=getHeight;
          run("Copy");
          close();
          if (stack==0) {
              newImage("RGB Stack", "RGB Black", width, height, n/2);
              stack = getImageID;
          }
          selectImage(stack);
          setSlice(i+1);
          run("Paste");
          index = indexOf(red, redSuffix);
          name = substring(red, 0, index);
          setMetadata(name);
          first += 2;
      }
      setSlice(1);
      run("Select None");
      setBatchMode(false);
  }

function openImagesAsStack4() {
      list = getFileList(dir2);
      setBatchMode(true);
      n = list.length;
      if ((n%4)!=0)
         exit("The number of files must be a multiple of 4");
      stack = 0;
      first = 0;
      for (i=0; i<n/4; i++) {
          showProgress(i+1, n/4);
          red="?"; green="?"; blue="?";
          for (j=first; j<first+4; j++) {
              if (indexOf(list[j], redSuffix)!=-1)
                  red = list[j];
              if (indexOf(list[j], greenSuffix)!=-1)
                  green = list[j];
              if (indexOf(list[j], blueSuffix)!=-1)
                  blue = list[j];
                 if (indexOf(list[j], graySuffix)!=-1)
                  gray = list[j];
          }
          open(dir2+red);
          open(dir2+green);
          open(dir2+blue);
            open(dir2+gray);
          run("Merge Channels...", "red=["+red+"] green=["+green+"] blue=["+blue+"] gray=["+gray+"] ");
          width=getWidth; height=getHeight;
          run("Copy");
          close();
          if (stack==0) {
              newImage("RGB Stack", "RGB Black", width, height, n/4);
              stack = getImageID;
          }
          selectImage(stack);
          setSlice(i+1);
          run("Paste");
          index = indexOf(red, redSuffix);
          name = substring(red, 0, index);
          setMetadata(name);
          first += 4;
      }
      setSlice(1);
      run("Select None");
      setBatchMode(false);
  }

function batchConvert() {
                        list = getFileList(dir2);
      setBatchMode(true);
      n = list.length;
      if ((n%3)!=0)
        exit("The number of files must be a multiple of 3");
      stack = 0;
      first = 0;
      for (i=0; i<n/3; i++) {
          showProgress(i+1, n/3);
          red="?"; blue="?";
          for (j=first; j<first+3; j++) {
              if (indexOf(list[j], redSuffix)!=-1)
                  red = list[j];
              if (indexOf(list[j], greenSuffix)!=-1)
                  green = list[j];
              if (indexOf(list[j], blueSuffix)!=-1)
                  blue = list[j];
          }
          open(dir2 +red);
                        open(dir2+green);
          open(dir2 +blue);
          run("Merge Channels...", "red=["+red+"] green=["+green+"] blue=["+blue+"] gray=*None* ");
          index = indexOf(red, redSuffix);
          name = substring(red, 0, index);
                        saveAs("tiff", dir3+name);
          first += 3;
      }
                }

function batchConvert2() {
                        list = getFileList(dir2);
      setBatchMode(true);
      n = list.length;
      if ((n%2)!=0)
        exit("The number of files must be a multiple of 2");
      stack = 0;
      first = 0;
      for (i=0; i<n/2; i++) {
          showProgress(i+1, n/2);
          red="?"; blue="?";
          for (j=first; j<first+2; j++) {
              if (indexOf(list[j], redSuffix)!=-1)
                  red = list[j];
              if (indexOf(list[j], blueSuffix)!=-1)
                  blue = list[j];
          }
          open(dir2 +red);
          open(dir2 +blue);
          run("Merge Channels...", "red=["+red+"] green=*None* blue=["+blue+"] gray=*None* ");
          index = indexOf(red, redSuffix);
          name = substring(red, 0, index);
                        saveAs("tiff", dir3+name);
          first += 2;
      }
                }

function batchConvert4() {
                        list = getFileList(dir2);
      setBatchMode(true);
      n = list.length;
      if ((n%4)!=0)
        exit("The number of files must be a multiple of 4");
      stack = 0;
      first = 0;
      for (i=0; i<n/4; i++) {
          showProgress(i+1, n/4);
          red="?"; green="?"; blue="?"; gray="?";
          for (j=first; j<first+4; j++) {
              if (indexOf(list[j], redSuffix)!=-1)
                  red = list[j];
              if (indexOf(list[j], blueSuffix)!=-1)
                  blue = list[j];
                if (indexOf(list[j], graySuffix)!=-1)
                  gray = list[j];
                if (indexOf(list[j], greenSuffix)!=-1)
                  green = list[j];
          }
          open(dir2 +red);
          open(dir2 +green);
                        open(dir2 +blue);
                        open(dir2 +gray);
          run("Merge Channels...", "red=["+red+"] green=["+red+"] blue=["+blue+"] gray=["+gray+"] ");
          index = indexOf(red, redSuffix);
          name = substring(red, 0, index);
                        saveAs("tiff", dir3+name);
          first += 4;
      }
                }
Reply | Threaded
Open this post in threaded view
|

Re: Macro Broken since updating to ImageJ 1.46m

Rasband, Wayne (NIH/NIMH) [E]
On May 8, 2012, at 5:07 PM, ajspracklen wrote:

> I cobbled together the macro that appears below to allow me to batch convert
> zeiss lsm files into individual .tiff files for each channel. After some
> user input, it will also batch merge the specified channels into a single
> image. However, after recently updating both the FIJI distribution of ImageJ
> and ImageJ, this macro has been rendered broken. As best I can figure, it
> has something to do with setting it to run in batch mode. Any help/advice to
> get this macro up and running again would be great! Thank you in advance.

Are you getting this exception?

  java.lang.NullPointerException: null
    at org.imagearchive.lsm.reader.Reader.open(Reader.java:62)
    at LSM_Reader.run(LSM_Reader.java:46)
    at ij.IJ.runUserPlugIn(IJ.java:184)
    at ij.IJ.runPlugIn(IJ.java:151)
    at ij.IJ.runPlugIn(IJ.java:140)
    at HandleExtraFileTypes.tryPlugIn(HandleExtraFileTypes.java:402)

If so, you have encountered the "LSM reader doesn't work with setBatchMode(true)" bug at

   http://fiji.sc/cgi-bin/bugzilla/show_bug.cgi?id=422

You can work around this bug by switching to ImageJ or by using the Bio-Formats plugin instead of the LSM_Reader.

-wayne


> //will batch ssplit/merge image files using user defined parameters
> //
> //add: macro "Batch Split/Merge LSM Files"{
> //      runMacro("Batch merge LSM v2");
> //              }
> //to startupmacros.txt
> dir1 = getDirectory("Choose Source Directory");
> list = getFileList(dir1);
> dir2 = dir1+"Split"+File.separator;
> dir3 = dir1+"Merge"+File.separator;
> File.makeDirectory(dir2)
> File.makeDirectory(dir3)
> Dialog.create("How many channels?");
> Dialog.addChoice("Channels:", newArray("2", "3", "4"));
> Dialog.show();
> channels = Dialog.getChoice;
>
> if ((channels=="2")) {
> splitmerge2();
> }
> else if ((channels=="3")) {
> splitmerge3();
> }
> else if ((channels=="4")) {
> splitmerge4();
> }
>
> function splitmerge2(){
> for (i=0; i<list.length; i++)
>        {
>
>        if (File.isDirectory(dir1+list[i])){}
>        else{
>
>                        path = dir1+list[i];
>                        if (endsWith(path, &quot;.db&quot;)){}
>                        else{
>
>                                setBatchMode(true);
>                                open(path);
>                                if (bitDepth!=8){}
>                                else {
>
>                                                title = File.nameWithoutExtension ;
>                                                run(&quot;Split Channels&quot;);
>
>                                                //saveAs(&quot;Tiff&quot;, dir2+title+&quot;c3.tif&quot;);
>                                                //close();
>                                                saveAs(&quot;Tiff&quot;, dir2+title+&quot;c2.tif&quot;);
>                                                close();
>                                                saveAs(&quot;Tiff&quot;, dir2+title+&quot;c1.tif&quot;);
>                                                close();
>                                                setBatchMode(false);
>
>                                                }
>                                        }
>                                }
>                        }
> }
>
> function splitmerge3(){
> for (i=0; i&lt;list.length; i++)
>        {
>
>        if (File.isDirectory(dir1+list[i])){}
>        else{
>
>                        path = dir1+list[i];
>                        if (endsWith(path, &quot;.db&quot;)){}
>                        else{
>
>                                setBatchMode(true);
>                                open(path);
>                                if (bitDepth!=8){}
>                                else {
>
>                                                title = File.nameWithoutExtension ;
>                                                run(&quot;Split Channels&quot;);
>
>                                                saveAs(&quot;Tiff&quot;, dir2+title+&quot;c3.tif&quot;);
>                                                close();
>                                                saveAs(&quot;Tiff&quot;, dir2+title+&quot;c2.tif&quot;);
>                                                close();
>                                                saveAs(&quot;Tiff&quot;, dir2+title+&quot;c1.tif&quot;);
>                                                close();
>                                                setBatchMode(false);
>
>                                                }
>                                        }
>                                }
>                        }
> }
>
> function splitmerge4(){
>
>
>
> for (i=0; i&lt;list.length; i++)
>        {
>
>        if (File.isDirectory(dir1+list[i])){}
>        else{
>
>                        path = dir1+list[i];
>                        if (endsWith(path, &quot;.db&quot;)){}
>                        else{
>
>                                setBatchMode(true);
>                                open(path);
>                                if (bitDepth!=8){}
>                                else {
>
>                                                title = File.nameWithoutExtension ;
>                                                run(&quot;Split Channels&quot;);
>
>                                                saveAs(&quot;Tiff&quot;, dir2+title+&quot;c4.tif&quot;);
>                                                close();
>                                                saveAs(&quot;Tiff&quot;, dir2+title+&quot;c3.tif&quot;);
>                                                close();
>                                                saveAs(&quot;Tiff&quot;, dir2+title+&quot;c2.tif&quot;);
>                                                close();
>                                                saveAs(&quot;Tiff&quot;, dir2+title+&quot;c1.tif&quot;);
>                                                close();
>                                                setBatchMode(false);
>
>                                                }
>                                        }
>                                }
>                        }
> }
>
> Dialog.create(&quot;Batch Merge&quot;);
> Dialog.addChoice(&quot;Channels:&quot;, newArray(&quot;2&quot;,
> &quot;3&quot;, &quot;4&quot;));
> Dialog.show();
> channels = Dialog.getChoice;
>        if (channels==2) {
>                Dialog.create(&quot;Chanel Order&quot;);
>                Dialog.addString(&quot;Blue:&quot;, &quot;c1&quot;);
>                Dialog.addString(&quot;Red:&quot;, &quot;c2&quot;);
>                Dialog.addCheckbox(&quot;Open as Stack&quot;, false);
>                Dialog.show();
>
>                blueSuffix = Dialog.getString() + &quot;.&quot;;
>                redSuffix = Dialog.getString() + &quot;.&quot;;
>                openAsStack = Dialog.getCheckbox();
>                if (openAsStack)
>                        openImagesAsStack2();
>                else
>                        batchConvert2();
>                exit;
>        }
>        else if ((channels==3)) {
>                Dialog.create(&quot;Chanel Order&quot;);
>                Dialog.addString(&quot;Blue:&quot;, &quot;c1&quot;);
>                Dialog.addString(&quot;Green:&quot;, &quot;c2&quot;);
>                Dialog.addString(&quot;Red:&quot;, &quot;c3&quot;);
>                Dialog.addCheckbox(&quot;Open as Stack&quot;, false);
>                Dialog.show();
>
>                blueSuffix = Dialog.getString() + &quot;.&quot;;
>                greenSuffix = Dialog.getString() + &quot;.&quot;;
>                redSuffix = Dialog.getString() + &quot;.&quot;;
>                openAsStack = Dialog.getCheckbox();
>                if (openAsStack)
>                        openImagesAsStack();
>                else
>                        batchConvert();
>                exit;
>        }
>        else if ((channels==4)) {
>                Dialog.create(&quot;Chanel Order&quot;);
>                Dialog.addString(&quot;Blue:&quot;, &quot;c1&quot;);
>                Dialog.addString(&quot;Green:&quot;, &quot;c2&quot;);
>                Dialog.addString(&quot;Red:&quot;, &quot;c3&quot;);
>                Dialog.addString(&quot;Far Red:&quot;, &quot;c4&quot;);
>                Dialog.addCheckbox(&quot;Open as Stack&quot;, false);
>                Dialog.show();
>
>                blueSuffix = Dialog.getString() + &quot;.&quot;;
>                greenSuffix = Dialog.getString() + &quot;.&quot;;
>                redSuffix = Dialog.getString() + &quot;.&quot;;
>                graySuffix = Dialog.getString() + &quot;.&quot;;
>                openAsStack = Dialog.getCheckbox();
>                if (openAsStack)
>                        openImagesAsStack4();
>                else
>                        batchConvert4();
>                exit;
>        }
>        else if ((channels&lt;=1)) {
>                Dialog.create(&quot;ERROR&quot;);
>                Dialog.addMessage(&quot;Number of channels must be 2, 3, or 4.&quot;);
>                Dialog.show();
>        }
>        else if ((channels>=5)) {
>                Dialog.create("ERROR");
>                Dialog.addMessage("Number of channels must be 2, 3, or 4.");
>                Dialog.show();
>        }
>
> function openImagesAsStack() {
>      list = getFileList(dir2);
>      setBatchMode(true);
>      n = list.length;
>      if ((n%3)!=0)
>         exit("The number of files must be a multiple of 3");
>      stack = 0;
>      first = 0;
>      for (i=0; i<n/3; i++) {
>          showProgress(i+1, n/3);
>          red="?"; green="?"; blue="?";
>          for (j=first; j<first+3; j++) {
>              if (indexOf(list[j], redSuffix)!=-1)
>                  red = list[j];
>              if (indexOf(list[j], greenSuffix)!=-1)
>                  green = list[j];
>              if (indexOf(list[j], blueSuffix)!=-1)
>                  blue = list[j];
>          }
>          open(dir2+red);
>          open(dir2+green);
>          open(dir2+blue);
>          run("Merge Channels...", "red=["+red+"] green=["+green+"]
> blue=["+blue+"] gray=*None* ");
>          width=getWidth; height=getHeight;
>          run("Copy");
>          close();
>          if (stack==0) {
>              newImage("RGB Stack", "RGB Black", width, height, n/3);
>              stack = getImageID;
>          }
>          selectImage(stack);
>          setSlice(i+1);
>          run("Paste");
>          index = indexOf(red, redSuffix);
>          name = substring(red, 0, index);
>          setMetadata(name);
>          first += 3;
>      }
>      setSlice(1);
>      run("Select None");
>      setBatchMode(false);
>  }
>
> function openImagesAsStack2() {
>      list = getFileList(dir2);
>      setBatchMode(true);
>      n = list.length;
>      if ((n%2)!=0)
>         exit("The number of files must be a multiple of 2");
>      stack = 0;
>      first = 0;
>      for (i=0; i<n/2; i++) {
>          showProgress(i+1, n/2);
>          red="?"; blue="?";
>          for (j=first; j<first+2; j++) {
>              if (indexOf(list[j], redSuffix)!=-1)
>                  red = list[j];
>              if (indexOf(list[j], blueSuffix)!=-1)
>                  blue = list[j];
>          }
>          open(dir2+red);
>          open(dir2+blue);
>          run("Merge Channels...", "red=["+red+"] green=*None*
> blue=["+blue+"] gray=*None* ");
>          width=getWidth; height=getHeight;
>          run("Copy");
>          close();
>          if (stack==0) {
>              newImage("RGB Stack", "RGB Black", width, height, n/2);
>              stack = getImageID;
>          }
>          selectImage(stack);
>          setSlice(i+1);
>          run("Paste");
>          index = indexOf(red, redSuffix);
>          name = substring(red, 0, index);
>          setMetadata(name);
>          first += 2;
>      }
>      setSlice(1);
>      run("Select None");
>      setBatchMode(false);
>  }
>
> function openImagesAsStack4() {
>      list = getFileList(dir2);
>      setBatchMode(true);
>      n = list.length;
>      if ((n%4)!=0)
>         exit("The number of files must be a multiple of 4");
>      stack = 0;
>      first = 0;
>      for (i=0; i<n/4; i++) {
>          showProgress(i+1, n/4);
>          red="?"; green="?"; blue="?";
>          for (j=first; j<first+4; j++) {
>              if (indexOf(list[j], redSuffix)!=-1)
>                  red = list[j];
>              if (indexOf(list[j], greenSuffix)!=-1)
>                  green = list[j];
>              if (indexOf(list[j], blueSuffix)!=-1)
>                  blue = list[j];
>                 if (indexOf(list[j], graySuffix)!=-1)
>                  gray = list[j];
>          }
>          open(dir2+red);
>          open(dir2+green);
>          open(dir2+blue);
>            open(dir2+gray);
>          run("Merge Channels...", "red=["+red+"] green=["+green+"]
> blue=["+blue+"] gray=["+gray+"] ");
>          width=getWidth; height=getHeight;
>          run("Copy");
>          close();
>          if (stack==0) {
>              newImage("RGB Stack", "RGB Black", width, height, n/4);
>              stack = getImageID;
>          }
>          selectImage(stack);
>          setSlice(i+1);
>          run("Paste");
>          index = indexOf(red, redSuffix);
>          name = substring(red, 0, index);
>          setMetadata(name);
>          first += 4;
>      }
>      setSlice(1);
>      run("Select None");
>      setBatchMode(false);
>  }
>
> function batchConvert() {
>                        list = getFileList(dir2);
>                        setBatchMode(true);
>                        n = list.length;
>                        if ((n%3)!=0)
>                                exit("The number of files must be a multiple of 3");
>                        stack = 0;
>                        first = 0;
>                        for (i=0; i<n/3; i++) {
>                        showProgress(i+1, n/3);
>                         red="?"; blue="?";
>                        for (j=first; j<first+3; j++) {
>                if (indexOf(list[j], redSuffix)!=-1)
>                                red = list[j];
>                if (indexOf(list[j], greenSuffix)!=-1)
>                                green = list[j];
>                if (indexOf(list[j], blueSuffix)!=-1)
>                                blue = list[j];
>          }
>                        open(dir2 +red);
>                        open(dir2+green);
>                        open(dir2 +blue);
>                        run("Merge Channels...", "red=["+red+"] green=["+green+"]
> blue=["+blue+"] gray=*None* ");
>                        index = indexOf(red, redSuffix);
>                        name = substring(red, 0, index);
>                        saveAs("tiff", dir3+name);
>                        first += 3;
>                        }
>                }
>
> function batchConvert2() {
>                        list = getFileList(dir2);
>                        setBatchMode(true);
>                        n = list.length;
>                        if ((n%2)!=0)
>                                exit("The number of files must be a multiple of 2");
>                        stack = 0;
>                        first = 0;
>                        for (i=0; i<n/2; i++) {
>                        showProgress(i+1, n/2);
>                         red="?"; blue="?";
>                        for (j=first; j<first+2; j++) {
>                if (indexOf(list[j], redSuffix)!=-1)
>                                red = list[j];
>                if (indexOf(list[j], blueSuffix)!=-1)
>                                blue = list[j];
>          }
>                        open(dir2 +red);
>                        open(dir2 +blue);
>                        run("Merge Channels...", "red=["+red+"] green=*None*
> blue=["+blue+"] gray=*None* ");
>                        index = indexOf(red, redSuffix);
>                        name = substring(red, 0, index);
>                        saveAs("tiff", dir3+name);
>                        first += 2;
>                        }
>                }
>
> function batchConvert4() {
>                        list = getFileList(dir2);
>                        setBatchMode(true);
>                        n = list.length;
>                        if ((n%4)!=0)
>                                exit("The number of files must be a multiple of 4");
>                        stack = 0;
>                        first = 0;
>                        for (i=0; i<n/4; i++) {
>                        showProgress(i+1, n/4);
>                         red="?"; green="?"; blue="?"; gray="?";
>                        for (j=first; j<first+4; j++) {
>                if (indexOf(list[j], redSuffix)!=-1)
>                                red = list[j];
>                if (indexOf(list[j], blueSuffix)!=-1)
>                                blue = list[j];
>                if (indexOf(list[j], graySuffix)!=-1)
>                                gray = list[j];
>                if (indexOf(list[j], greenSuffix)!=-1)
>                                green = list[j];
>          }
>                        open(dir2 +red);
>                        open(dir2 +green);
>                        open(dir2 +blue);
>                        open(dir2 +gray);
>                        run("Merge Channels...", "red=["+red+"] green=["+red+"]
> blue=["+blue+"] gray=["+gray+"] ");
>                        index = indexOf(red, redSuffix);
>                        name = substring(red, 0, index);
>                        saveAs("tiff", dir3+name);
>                        first += 4;
>                        }
>                }
>
> --
> View this message in context: http://imagej.1557.n6.nabble.com/Macro-Broken-since-updating-to-ImageJ-1-46m-tp4961463.html
> Sent from the ImageJ mailing list archive at Nabble.com.