I am trying to use the particle analyzer in python. I found an example
for use of the PA on stacks, in which the PA is run on each slice individually within a loop. Is there a way to run the PA on the entire stack, without having to loop over each slice? I looked for an example of this, and I am sure there must be many such examples, but I did not find it. Thanks in advance --aryeh -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Jul 6, 2014, at 6:24 AM, Aryeh Weiss wrote:
> I am trying to use the particle analyzer in python. I found an example for use of the PA on stacks, in which the PA is run on each slice individually within a loop. Is there a way to run the PA on the entire stack, without having to loop over each slice? > I looked for an example of this, and I am sure there must be many such examples, but I did not find it. Try using the command recorder (Plugins>Macros>Record). The following is what is recorded when I open the "Bat Cochlea Volume" sample stack, threshold it and run the particle analyzer, with the recorder running in "JavaScript" mode. IJ.run("Set Measurements...", "area centroid stack decimal=3"); imp = IJ.openImage("http://imagej.nih.gov/ij/images/bat-cochlea-volume.zip"); IJ.setAutoThreshold(imp, "Default dark"); IJ.run(imp, "Analyze Particles...", "size=10 display clear summarize stack"); -wayne -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On 7/6/14, 11:57 PM, Rasband, Wayne (NIH/NIMH) [E] wrote:
> On Jul 6, 2014, at 6:24 AM, Aryeh Weiss wrote: > >> I am trying to use the particle analyzer in python. I found an example for use of the PA on stacks, in which the PA is run on each slice individually within a loop. Is there a way to run the PA on the entire stack, without having to loop over each slice? >> I looked for an example of this, and I am sure there must be many such examples, but I did not find it. > Try using the command recorder (Plugins>Macros>Record). The following is what is recorded when I open the "Bat Cochlea Volume" sample stack, threshold it and run the particle analyzer, with the recorder running in "JavaScript" mode. > > IJ.run("Set Measurements...", "area centroid stack decimal=3"); > imp = IJ.openImage("http://imagej.nih.gov/ij/images/bat-cochlea-volume.zip"); > IJ.setAutoThreshold(imp, "Default dark"); > IJ.run(imp, "Analyze Particles...", "size=10 display clear summarize stack"); > > -wayne > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > I was trying to do it using the the ParticleAnalyzer class without IJ.run . Is there a way to do that? For that matter, is it generally better to use the API rather than use IJ.run ? --aryeh -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On 7/7/14, 9:14 AM, Paul van Schayck wrote:
> Dear Aryeh, > > On Mon, Jul 7, 2014 at 4:43 AM, Aryeh Weiss <[hidden email]> wrote: >> I was trying to do it using the the ParticleAnalyzer class without IJ.run . >> Is there a way to do that? For that matter, is it generally better to use >> the API rather than use >> IJ.run ? > That's certainly possible. And probably as you already found in your > example. You can do something like this (this is Javascript, but can > be adapted to Python > > table = new ResultsTable() > pa = ParticleAnalyzer(0, Measurements.CENTER_OF_MASS, table, > 300,Number.POSITIVE_INFINITY, 0.4, 1.0) > pa.analyze(imp) > > // Loop through objects and store them in list object > r = [] > for (i=0; i < table.getCounter(); i++) { > r[i] = { "XM": table.getValue("XM",i), "YM": table.getValue("YM",i) } > } > > I'm not sure what drawback you find with looping through the stacks. > Internally, this is what Analyze Particle plugin is doing internally > as well AFAIK. > > Kind regards, > > Paul > Thank you for your reply. I have a student who is converting some algorithms which I implemented as macros to python. I thought that it would be cleaner (and maybe more efficient) to have the analyzer operate on the stack, just as in the macro I have a "stack" keyword. Also, if I generate a mask, I prefer that a stack be generated, rather then get each slice, and append it to a stack (although that can certainly be done). The API docs mention processStack, which appears to be a flag that tell it to process a stack (just a guess), but I dont know how to use it. Best regards, --aryeh -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Aryeh,
On Mon, Jul 7, 2014 at 8:57 AM, Aryeh Weiss <[hidden email]> wrote: > Thank you for your reply. > I have a student who is converting some algorithms which I implemented as > macros to python. > I thought that it would be cleaner (and maybe more efficient) to have the > analyzer operate on the stack, > just as in the macro I have a "stack" keyword. > Also, if I generate a mask, I prefer that a stack be generated, rather then > get each slice, and append it to a stack > (although that can certainly be done). > > The API docs mention processStack, which appears to be a flag that tell it > to process a stack (just a guess), but I dont know how to use it. > As far as I can tell from the ParticleAnalyzer code [1], this really an internal option for the run() method. But maybe someone more familiar with that code should comment on that. Paul [1] https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/ParticleAnalyzer.java -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |