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 |
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 |
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 > > > |
In reply to this post by lechristophe
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 |
Dear
If you only set a threshold and don't apply it, I believe you should also add "limit" to the measurement settings. Kind regards, winnok -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Adam Cliffe Sent: woensdag 7 mei 2008 11:14 To: [hidden email] Subject: Re: macro loop Analyze Particles 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 No virus found in this incoming message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.23.9/1417 - Release Date: 6/05/2008 8:07 No virus found in this outgoing message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.23.9/1417 - Release Date: 6/05/2008 8:07 |
In reply to this post by lechristophe
Hi Christophe,
nSlices is a function, not a variable, and it relates to the current foreground image. You may use parentheses, nSlices() but you need not. http://rsb.info.nih.gov/ij/developer/macro/functions.html#N Michael ________________________________________________________________ On 7 May 2008, at 11:07, Christophe Leterrier wrote: > 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 >>> >> |
Free forum by Nabble | Edit this page |