Macro for measuring several ROIs

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

Macro for measuring several ROIs

tisalon
'm creating a script for automated measuring fluorescence intensity. I have done some progress, the macro opens the image, split in as many channels as I have and perform some trasformation so that it is possible to execute particle analysis at image 1. Then, what I want is to measure all the created ROIs but I am stacked at this point:

here is my code

 dir1 = getDirectory("Choose Source 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(false);                                                                 // 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");


        saveAs("Results", dir1+name+"c02"+ ".txt");
  }                                                                                   // move on to next original stack in the folder

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Macro for measuring several ROIs

odedm
Hi
I'm not sure why you have multiple brightness contrast enhancers, or 2 make binary commands
you can ananlyse multiple channel images in composite mode by using the multimeasure command from the roi mananger

if you have a good segmentation and selection just use
roiManager("add");
roiManager("measure");

then you get the results with
getResults(); command (look in the imagej builtin functions)

hope that helps

<quote author="tisalon">
'm creating a script for automated measuring fluorescence intensity. I have done some progress, the macro opens the image, split in as many channels as I have and perform some trasformation so that it is possible to execute particle analysis at image 1. Then, what I want is to measure all the created ROIs but I am stacked at this point:

here is my code

 dir1 = getDirectory("Choose Source 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(false);                                                                 // 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");


        saveAs("Results", dir1+name+"c02"+ ".txt");
  }                                                                                   // move on to next original stack in the folder

Thanks
</quote>