Login  Register

Re: macro loop Analyze Particles

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

But the first instruction of the loop is
selectImage(StackID);
before the setSlice command...so how come it doesn't select the stack
? would it be possible that it reevaluates the "nSlices" variable in
the for arguments with the current active image ? So the best would be
to store the number of slices of the source stack as a fixed variable
and loop on that...

I'll try, thanks !



On Wed, May 7, 2008 at 10:57 AM, Michael Schmid <[hidden email]> wrote:

> Hi Christophe,
>
>  after the loop runs once, it seems that the foreground image is
>  the mask, and the mask has only one slice.
>  You have to add
>   selectImage(StackID);
>  before the end of the loop.
>
>  Michael
>  ________________________________________________________________
>
>
>
>  On 7 May 2008, at 10: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
> >
>