Help with macro iterating slices of a stack

Posted by Pedro J CamelloDr Pedro J Camello on
URL: http://imagej.273.s1.nabble.com/Help-with-macro-iterating-slices-of-a-stack-tp5023279.html

Hi all,

I´m stuck with a macro written to iterate on all the slices of a binary stack.
In each slice, the code below should run Analyze particles, place the particles in the ROI Manager and Measure all of them.
The problem is that, after the first iteration, once i=2 the code does not generate a set of ROIs in the ROI Manager (line 8).

I can´t understand why the Analyze particles command runs in the first instance and fails afterwards…

I don´t want the Analyze particles command to run all the slices because I want to Measure each slice separately (maybe I could arrange it using the labels column of the Results table, but I would prefer to avoid it)

Any help will be welcome

Code:
1  // Up to this point I have a binary stack with all the nuclei (watershed) ready to be counted;
2  for (i=1; i<nSlices+1;i++) {
3   Stack.setSlice(i);
4   Stack.getPosition(channel, slice, frame);
5   print("Slice number = "+slice); //Just to check the slice number
6  // waitForUser("Check i and slice", "i =  "+i+"  Slice  =  "+slice);
7   run("Set Measurements...", "area display redirect=None decimal=2");
8   run("Analyze Particles...", "size=150-Infinity pixel clear include add slice");
9  // waitForUser("Check rois OK", "Ther are   "+roiManager("count")+" ROIs");  
10   roiManager("multi-measure");
12   print("Slice num = " +slice+"Cells = "+roiManager("count")); roiManager("reset");
13  }

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html