Re: Help with macro iterating slices of a stack

Posted by CARL Philippe (LBP) on
URL: http://imagej.273.s1.nabble.com/Help-with-macro-iterating-slices-of-a-stack-tp5023279p5023281.html

Hola Pedro,
Your code is way too complicated for things that can be done way more easily..
Indeed, within the "Analyze Particles..." tool you have already the possibility to go through the whole stack (with the option "stack") as well as measure the parameters set within "Set Measurements..." by activating the option "display".
The following macro demonstrates how easy and short your code could alternatively be:
        run("Bat Cochlea Volume");
        run("Set Measurements...", "area display redirect=None decimal=2");
        run("Analyze Particles...", "display clear include add stack");
Quod erat demonstrandum!
My best regards,
Philippe

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 42 89

----- Le 3 Mai 20, à 17:18, Pedro J Camello [hidden email] a écrit :

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

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