Login  Register

Re: macro loop Analyze Particles

Posted by AdamC on May 07, 2008; 9:13am
URL: http://imagej.273.s1.nabble.com/macro-loop-Analyze-Particles-tp3696311p3696315.html

I think it doesn't like the fact you don't define nSlices.

I added the line
Slice=nSlices
and changed k<nSlices to k<Slices

I think this fixes it:

adam


//code starts

macro "multi_detector" {
     run("Set Scale...", "distance=0 known=1 pixel=1 unit=pixel");
     run("Set Measurements...", "area mean circularity feret's  
integrated slice redirect=None decimal=3");
     StackID=getImageID();
     Slices=nSlices; //Line changed by Adam
     print("\\Clear");
     print("start");
     print("source ID "+StackID);
     print(nSlices+" slices");

     for (k=0; k<Slices; k++) { //Changed by Adam
         print("begin loop slice "+(k+1));
         selectImage(StackID);
         setSlice(k+1);
         setAutoThreshold();
         run("Analyze Particles...", "size=50-Infinity  
circularity=0.00-1.00 show=Masks display record slice");
         print("AP slice "+(k+1)+" done");
         MASK1ID=getImageID();
         print("mask ID for slice"+(k+1)+":"+MASK1ID);
     }
print("finished");
}


// code ends
On 7 May 2008, at 16:38, Christophe Leterrier wrote:

> Dear ImageJers,
>
> I'm totally confused about a piece of macro code I'm trying to debug
> with no success. I want to analyze particles for each slice of a
> stack, but I want to have an automatic threshold detection for each
> slice separately (as the intensity levels of the objects can be very
> different from one slice to another), so I cannot just launch the
> Analyze Particle command for the whole stack. I've tested that if you
> trigger an AutoThreshold for each slice and then do an Analyze
> Particle with the "slice" argument, it will do what I want.
>
> So I just want to loop that for each slice, and I've written this  
> piece of code:
>
>
> //code starts
>
> macro "multi_detector" {
>     run("Set Scale...", "distance=0 known=1 pixel=1 unit=pixel");
>     run("Set Measurements...", "area mean circularity feret's
> integrated slice redirect=None decimal=3");
>     StackID=getImageID();
>     print("\\Clear");
>     print("start");
>     print("source ID "+StackID);
>     print(nSlices+" slices");
>
>     for (k=0; k<nSlices; k++) {
>         print("begin loop slice "+(k+1));
>         selectImage(StackID);
>         setSlice(k+1);
>         setAutoThreshold();
>         run("Analyze Particles...", "size=50-Infinity
> circularity=0.00-1.00 show=Masks display record slice");
>         print("AP slice "+(k+1)+" done");
>         MASK1ID=getImageID();
>         print("mask ID for slice"+(k+1)+":"+MASK1ID);
>     }
> print("finished");
> }
>
>
> // code ends
>
> But the "for" loop doesn't work ! It does the first slice and then
> finishes. What is the problem here ? I'm sure it is something evident
> but I can't find what... I've added a lot of prints for debugging but
> the macro is just a couple of instructions, and I can't manage to find
> what's wrong. By the way, this is IJ 1.41a with Java 1.6 dp under OSX
> 10.4.
>
> On a related note, having an option in the Analyze Particles command
> to batch the Analyze Particle on a stack with a different automatic
> threshold for each slice would be great, so my macro would shrink to
> one line, and I would'nt have to reconstruct the mask stack
> afterwars...
>
> Thank you for your help,
>
> Christophe

Dr Adam Cliffe
Research Fellow
Rørth Lab
Cell Migration Group
Temasek Lifescience Laboratory
1 Research Link
National University of Singapore
Singapore 117604

tel: (65) 6872 8406
fax: (65) 6872 7007