Problem with Batch mode

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

Problem with Batch mode

tisalon
   Dear all;

I'm here trying to create a macro that can make some measurements over a stack of pictures. The script works perfectly when I execute on individual pictures (  setBatchMode(false);) but when I activate the batch mode (switch to"true")  it gets completely useless because it does not perform any measurement, rather it returns a sort of summary. Here is my code, I am running ImageJ 1.5 controlled from Fiji. I would appreciate any kind of help!

Thanks

  // start of "saving with suffices" path
    // The "saving with suffices" path:
    // Working with this path splits all multipage tiff in one folder into several substacks.
    // These substacks are stored in the same folder as the original stacks under the name of the original stack with a suffix containing the number of the substack.
    // All original stacks in a folder should be dividable into the same number of substacks. The latter can range from 2 to 99, the default value is 3.
      dir1 = getDirectory("Choose Source Directory ");
      dir2 = getDirectory("Choose Results Directory ");

      list = getFileList(dir1);                                                           // get the list of all filenames in the directory
      subst = 3;                                                                          // set the "subst" variable to 3
      Dialog.create("BatchSplitStacks");                                                  // create a dialogue to change the stack divisor
      Dialog.addNumber("Number of substacks:", subst);                                    // in the dialogue, get the number of substacks, default is "subst" (=3)
      Dialog.show();                                                                      // show the above created dialogue
      chan = Dialog.getNumber();                                                          // the stack divisor is defined
      setBatchMode(true);                                                                 // do not show the images while processing them
      for (i=0; i<list.length; i++) {                                                     // go through the files of the folder
          showProgress(i+1, list.length);                                                 // the progress of the processing of the actual stack is shown in the ImageJ window
          open(dir1+list[i]);                                                             // open an original stack
          name = list[i];                                                                 // get the filename of the original stack
          run("Stack Splitter", "number="+chan);                                          // run the Stack Splitter plugin with the defined divisor
          for (e=0; e<chan; e++) {                                                        // for each substack a saving routine is run
             dotIndex = lastIndexOf(name, ".");                                           // this line and the following line I took from another macro but I do not know
                                                                              // substacks with a number below 10 are saved with a suffix and a 2 digit extension (e.g. 01 instead of the standard 1)
                 saveAs("tiff", dir1+"c0"+e+".tif");
              close();
                                                                              // closing substack
          }                                                                               // next saving routine
                         close(); // closing current original stack

                         open(dir1+"c02.tif");
                          run("Enhance Contrast", "saturated=0.35");
                                                  run("Enhance Contrast", "saturated=0.35");
  run("Enhance Contrast", "saturated=0.35");
  setAutoThreshold("Default");
  setAutoThreshold("Default dark");
  run("Make Binary");
  run("Make Binary");
  run("Watershed");
  run("Analyze Particles...", "size=0.30-50.00 circularity=0.00-0.70 show=Masks display summarize add in_situ");
 
  open(dir1+"c01.tif");
  run("Subtract Background...", "rolling=50");
  run("Enhance Contrast", "saturated=0.35");
 
          n = roiManager("count");
  for (i=0; i<n; i++) {
      roiManager("select", i);
      getStatistics(area, mean);
      setResult("Area",  i, area);
      setResult("Mean", i, mean);
  }
  updateResults();
  saveAs("Results", dir2+name+"c02"+ ".txt");
  open(dir1+"c00.tif");
   run("Subtract Background...", "rolling=50");
   run("Enhance Contrast", "saturated=0.35");
                                                  run("Enhance Contrast", "saturated=0.35");
  run("Enhance Contrast", "saturated=0.35");
   for (i=0; i<n; i++) {
      roiManager("select", i);
      getStatistics(area, mean);
      setResult("Area",  i, area);
      setResult("Mean", i, mean);
  }
    updateResults();
  saveAs("Results", dir2+name+"c00"+ ".txt");
 
      }                                                                                   // move on to next original stack in the folder
roiManager("Select All");
roiManager("Delete");    
run("Clear Results");