Some years ago I asked how to process stacks using the ParticleAnalyzer
class. Here is the thread: Imagej.1557.x6.nabble.com/ParticleAnalyzer-class-and-stacks-td5008596.html However, I did not solve it, and I apparently let it drop. Now I am trying again. Here is a code snippet that get a stack, but only works on the first slice. ######################## # set up the parameters for the particle analyzer minSize = 1 # pixels; We need to find a better basis for setting a lower limit maxSize = width*height minCirc = 0.0 maxCirc = 1.0 options = PA.SHOW_RESULTS+PA.EXCLUDE_EDGE_PARTICLES+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS measurements = Measurements.ALL_STATS rt = ResultsTable() pa = PA(options, measurements, rt, minSize, maxSize, minCirc, maxCirc) print pa.processStack pa.analyze(lblImp, lblImp.getProcessor()) ######################## A few thins to note: 1. I set DOES_STACK. The PA code indicates that if this is done, and the image is a stack, then the protected variable processStack will be True. 2. I checked pa.processStack, and it is indeed True (pa is my instance of the ParticleAnalyzer). 3. I checked the stack size of lblImp, and it is 11 (that is, greater than 1) 4. I tried feeding pa.analyze an ImageStack - it did not want that (cannot coerce to ImageProcessor) 5. I tried feeding pa.analyze the ImageProcessor, but that produces the same result (only one mage processed). I tried giving it a StackProcessor, but again, that cannot be coerced to an ImageProcessor. I ran the Particle Analyzer using the use interface to verify that it runs on my image and can process the entire stack. I can loop through the ImageProcessors of the stack slices (imageStack.getProcessor(n)), but it seems to me that the class is capable of processing stacks, so my question is how? 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 |
More PA strangeness. In the test script just below this text, I expect
to include Slice and Mode in my measurements. I wrote the script as something minimal to see if I can get the PA class to work on the entire stack , or to demonstrate that it does not. Indeed it does not work on the entire stack, but in addition, Mode and Slice do not appear in the ResultsTable rt. This is strange because in my "large" script from which I took this code, I do get Mode and Slice. Also, even in the test script, rt.getColumnIndex("Mode") and rt.getColumnIndex("Slice") appear to return correct values for where those columns should be. When I run Analyze Particle from the GUI , all works as expected, Mode is in column 3 (Area is column 0), and Slice is in column 26 (my script says 27). So I am confused. Below is a script that should work on other installations, so maybe some of you can tell me if you get similar results. The output of the print statements is below the script. Thanks in advance --aryeh ################################################# ########### ParticleAnalyzer class test script################## from ij import IJ,ImagePlus from ij.plugin.filter import Analyzer, ParticleAnalyzer as PA from ij.plugin.frame import RoiManager from ij.measure import ResultsTable, Measurements from ij.process import ImageProcessor def testPA(imp): lblImp=imp.duplicate() width, height, nChannels, nSlices, nFrames = lblImp.getDimensions() IJ.setRawThreshold(lblImp, 50, 65535, "Red") lblImp.show() lblImp.setSlice(40) # set up the parameters for the particle analyzer minSize = 1 # pixels; We need to find a better basis for setting a lower limit maxSize = width*height # This is a weak upper bound. If the ROI is close to this, the segmentation is wrong minCirc = 0.0 maxCirc = 1.0 options = PA.SHOW_RESULTS+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS measurementsPA = Measurements.ALL_STATS+Measurements.STACK_POSITION+Measurements.SLICE+Measurements.MODE rt = ResultsTable() pa = PA(options, measurementsPA, rt, minSize, maxSize, minCirc, maxCirc) print "processStack = ", pa.processStack print "StackSize = ", lblImp.getStackSize() pa.analyze(lblImp) rm = RoiManager().getInstance() rt.updateResults() rt.show("Results") print "Area column index: ", rt.getColumnIndex("Area") print "Mode column index: ", rt.getColumnIndex("Mode") print "Slice column index: ", rt.getColumnIndex("Slice") areas = rt.getColumn(rt.getColumnIndex("Area")) means = rt.getColumn(rt.getColumnIndex("Mode")) slices = rt.getColumn(rt.getColumnIndex("Slice")) print slices, "\n", means, "\n", areas inputImp = IJ.openImage("http://imagej.nih.gov/ij/images/t1-head.zip") testPA(inputImp) ########### end of ParticleAnalyzer class test script############# ################################################ ##Script output: processStack = True StackSize = 129 Area column index: 0 Mode column index: 3 Slice column index: 27 None None array('f', [35586.0703125, 2.250004529953003, 6.75001335144043, 2.250004529953003, 2.250004529953003, 2.250004529953003, 2.250004529953003, 4.500009059906006, 78.75016021728516, 2.250004529953003, 11.250022888183594]) ## End of script output On 27/08/2019 12:20, Aryeh Weiss wrote: > Some years ago I asked how to process stacks using the > ParticleAnalyzer class. Here is the thread: > Imagej.1557.x6.nabble.com/ParticleAnalyzer-class-and-stacks-td5008596.html > > > However, I did not solve it, and I apparently let it drop. Now I am > trying again. Here is a code snippet that get a stack, but only works > on the first slice. > > ######################## > > # set up the parameters for the particle analyzer > minSize = 1 # pixels; We need to find a better basis for setting > a lower limit > maxSize = width*height > minCirc = 0.0 > maxCirc = 1.0 > options = > PA.SHOW_RESULTS+PA.EXCLUDE_EDGE_PARTICLES+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS > > measurements = Measurements.ALL_STATS > rt = ResultsTable() > > pa = PA(options, measurements, rt, minSize, maxSize, minCirc, > maxCirc) > print pa.processStack > pa.analyze(lblImp, lblImp.getProcessor()) > > ######################## > > A few thins to note: > > 1. I set DOES_STACK. The PA code indicates that if this is done, and > the image is a stack, then the protected variable processStack will be > True. > 2. I checked pa.processStack, and it is indeed True (pa is my instance > of the ParticleAnalyzer). > 3. I checked the stack size of lblImp, and it is 11 (that is, greater > than 1) > 4. I tried feeding pa.analyze an ImageStack - it did not want that > (cannot coerce to ImageProcessor) > 5. I tried feeding pa.analyze the ImageProcessor, but that produces > the same result (only one mage processed). I tried giving it a > StackProcessor, > but again, that cannot be coerced to an ImageProcessor. > > I ran the Particle Analyzer using the use interface to verify that it > runs on my image and can process the entire stack. > > I can loop through the ImageProcessors of the stack slices > (imageStack.getProcessor(n)), but it seems to me that the class is > capable of processing stacks, so my question is how? > > 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 |
In reply to this post by Aryeh Weiss
Hi Aryeh,
when called from the GUI, a macro, or IJ.run, the ParticleAnalyzer processes stacks via the usual method of PlugInFilters, where the run(ip) method of the PlugInFilter is called for each slice of the stack (this is done by the PlugInFIlterRunner). If you create a new ParticleAnalyzer with the desired options and then call it analyze method, it will work only on the current stack slice. See the source code at: https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/ParticleAnalyzer.java#L429 You have to call it repeatedly for all slices (ImpagePlus.setSlice) if you want to analyze the whole stack. Michael ________________________________________________________________________ On 27/08/2019 11:20 AM, Aryeh Weiss wrote: > Some years ago I asked how to process stacks using the ParticleAnalyzer class. Here is the thread: > Imagej.1557.x6.nabble.com/ParticleAnalyzer-class-and-stacks-td5008596.html > > However, I did not solve it, and I apparently let it drop. Now I am trying again. Here is a code snippet that get a stack, but only works on the first slice. > > ######################## > > # set up the parameters for the particle analyzer > minSize = 1 # pixels; We need to find a better basis for setting a lower limit > maxSize = width*height > minCirc = 0.0 > maxCirc = 1.0 > options = PA.SHOW_RESULTS+PA.EXCLUDE_EDGE_PARTICLES+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS > > measurements = Measurements.ALL_STATS > rt = ResultsTable() > > pa = PA(options, measurements, rt, minSize, maxSize, minCirc, maxCirc) > print pa.processStack > pa.analyze(lblImp, lblImp.getProcessor()) > > ######################## > > A few thins to note: > > 1. I set DOES_STACK. The PA code indicates that if this is done, and the image is a stack, then the protected variable processStack will be True. > 2. I checked pa.processStack, and it is indeed True (pa is my instance of the ParticleAnalyzer). > 3. I checked the stack size of lblImp, and it is 11 (that is, greater than 1) > 4. I tried feeding pa.analyze an ImageStack - it did not want that (cannot coerce to ImageProcessor) > 5. I tried feeding pa.analyze the ImageProcessor, but that produces the same result (only one mage processed). I tried giving it a StackProcessor, > but again, that cannot be coerced to an ImageProcessor. > > I ran the Particle Analyzer using the use interface to verify that it runs on my image and can process the entire stack. > > I can loop through the ImageProcessors of the stack slices (imageStack.getProcessor(n)), but it seems to me that the class is capable of processing stacks, so my question is how? > > Thanks in advance > --aryeh > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Aryeh Weiss
> On Aug 28, 2019, at 4:18 AM, Aryeh Weiss <[hidden email]> wrote:
> > More PA strangeness. In the test script just below this text, I expect to include Slice and Mode in my measurements. The ParticleAnalyzer class does not process stacks. It is the IJ.run() method that runs the particle analyzer on all the images in a stack. An easy way to get the ROIs of all the particles in a stack is to run the particle analyzer using IJ.run(), have it create an overlay, retrieve the ROIs from the overlay and use ImagePlus.getStatistics (or ImagePlus.getAllStatistics) to get the desired measurements. The following JavaScript example does this: -wayne img = IJ.openImage("http://imagej.nih.gov/ij/images/t1-head.zip") width = img.getWidth() height = img.getHeight() IJ.setRawThreshold(img, 50, 65535, "Red") maxSize = width*height options = "size=1-"+maxSize+" pixel show=Overlay clear stack" IJ.run(img, "Analyze Particles...", options); overlay = img.getOverlay() for (i=0; i<overlay.size(); i++) { roi = overlay.get(i) img.setRoi(roi) stats = img.getStatistics(); slice = roi.getPosition(); area = IJ.d2s(stats.area,2) mode = stats.mode print("roi="+i+", slice="+slice+", area="+area+", mode="+mode) } > I wrote the script as something minimal to see if I can get the PA class to work on the entire stack , or to demonstrate that it does not. > Indeed it does not work on the entire stack, but in addition, Mode and Slice do not appear in the ResultsTable rt. This is strange because in my "large" script from which I took this code, I do get Mode and Slice. Also, even in the test script, rt.getColumnIndex("Mode") and rt.getColumnIndex("Slice") appear > to return correct values for where those columns should be. When I run Analyze Particle from the GUI , all works as expected, Mode is in column 3 (Area is column 0), and Slice is in column 26 (my script says 27). So I am confused. Below is a script that should work on other installations, so maybe some of you can tell me if you get similar results. The output of the print statements is below the script. > > Thanks in advance > --aryeh > > > ################################################# > ########### ParticleAnalyzer class test script################## > > from ij import IJ,ImagePlus > from ij.plugin.filter import Analyzer, ParticleAnalyzer as PA > from ij.plugin.frame import RoiManager > from ij.measure import ResultsTable, Measurements > from ij.process import ImageProcessor > > def testPA(imp): > > lblImp=imp.duplicate() > > width, height, nChannels, nSlices, nFrames = lblImp.getDimensions() > > IJ.setRawThreshold(lblImp, 50, 65535, "Red") > lblImp.show() > lblImp.setSlice(40) > # set up the parameters for the particle analyzer > minSize = 1 # pixels; We need to find a better basis for setting a lower limit > maxSize = width*height # This is a weak upper bound. If the ROI is close to this, the segmentation is wrong > minCirc = 0.0 > maxCirc = 1.0 > options = PA.SHOW_RESULTS+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS > > measurementsPA = Measurements.ALL_STATS+Measurements.STACK_POSITION+Measurements.SLICE+Measurements.MODE > rt = ResultsTable() > > pa = PA(options, measurementsPA, rt, minSize, maxSize, minCirc, maxCirc) > print "processStack = ", pa.processStack > print "StackSize = ", lblImp.getStackSize() > > pa.analyze(lblImp) > rm = RoiManager().getInstance() > > rt.updateResults() > rt.show("Results") > print "Area column index: ", rt.getColumnIndex("Area") > print "Mode column index: ", rt.getColumnIndex("Mode") > print "Slice column index: ", rt.getColumnIndex("Slice") > areas = rt.getColumn(rt.getColumnIndex("Area")) > means = rt.getColumn(rt.getColumnIndex("Mode")) > slices = rt.getColumn(rt.getColumnIndex("Slice")) > print slices, "\n", means, "\n", areas > > inputImp = IJ.openImage("http://imagej.nih.gov/ij/images/t1-head.zip") > testPA(inputImp) > > ########### end of ParticleAnalyzer class test script############# > ################################################ > > ##Script output: > > processStack = True > StackSize = 129 > Area column index: 0 > Mode column index: 3 > Slice column index: 27 > None > None > array('f', [35586.0703125, 2.250004529953003, 6.75001335144043, 2.250004529953003, 2.250004529953003, 2.250004529953003, 2.250004529953003, 4.500009059906006, 78.75016021728516, 2.250004529953003, 11.250022888183594]) > > ## End of script output > > On 27/08/2019 12:20, Aryeh Weiss wrote: >> Some years ago I asked how to process stacks using the ParticleAnalyzer class. Here is the thread: >> Imagej.1557.x6.nabble.com/ParticleAnalyzer-class-and-stacks-td5008596.html >> >> However, I did not solve it, and I apparently let it drop. Now I am trying again. Here is a code snippet that get a stack, but only works on the first slice. >> >> ######################## >> >> # set up the parameters for the particle analyzer >> minSize = 1 # pixels; We need to find a better basis for setting a lower limit >> maxSize = width*height >> minCirc = 0.0 >> maxCirc = 1.0 >> options = PA.SHOW_RESULTS+PA.EXCLUDE_EDGE_PARTICLES+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS >> >> measurements = Measurements.ALL_STATS >> rt = ResultsTable() >> >> pa = PA(options, measurements, rt, minSize, maxSize, minCirc, maxCirc) >> print pa.processStack >> pa.analyze(lblImp, lblImp.getProcessor()) >> >> ######################## >> >> A few thins to note: >> >> 1. I set DOES_STACK. The PA code indicates that if this is done, and the image is a stack, then the protected variable processStack will be True. >> 2. I checked pa.processStack, and it is indeed True (pa is my instance of the ParticleAnalyzer). >> 3. I checked the stack size of lblImp, and it is 11 (that is, greater than 1) >> 4. I tried feeding pa.analyze an ImageStack - it did not want that (cannot coerce to ImageProcessor) >> 5. I tried feeding pa.analyze the ImageProcessor, but that produces the same result (only one mage processed). I tried giving it a StackProcessor, >> but again, that cannot be coerced to an ImageProcessor. >> >> I ran the Particle Analyzer using the use interface to verify that it runs on my image and can process the entire stack. >> >> I can loop through the ImageProcessors of the stack slices (imageStack.getProcessor(n)), but it seems to me that the class is capable of processing stacks, so my question is how? >> >> Thanks in advance >> --aryeh -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Michael Schmid
Hi Michael,
Thank you for your reply. I wonder what DOES_STACKS is for. I thought maybe it was to allow the PA to work on the selected slice, but that happens also without DOES_STACKS. This morning, i ran my test script, and it threw an error saying that pa has not attribute process.Stack. Yesterday it did not say this, and the source and docs seem to have it. Has the source just been changed? Also, why does the ResultsTable does not show columns for Slice and Mode in my test script. Note for the test script to run I now have to comment out print pa.processStack Best regards, --aryeh On 28/08/2019 20:58, Michael Schmid wrote: > Hi Aryeh, > > when called from the GUI, a macro, or IJ.run, the ParticleAnalyzer > processes stacks via the usual method of PlugInFilters, where the > run(ip) method of the PlugInFilter is called for each slice of the > stack (this is done by the PlugInFIlterRunner). If you create a new > ParticleAnalyzer with the desired options and then call it analyze > method, it will work only on the current stack slice. See the source > code at: > > > https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/ParticleAnalyzer.java#L429 > > > You have to call it repeatedly for all slices (ImpagePlus.setSlice) if > you want to analyze the whole stack. > > Michael > ________________________________________________________________________ > > On 27/08/2019 11:20 AM, Aryeh Weiss wrote: > > Some years ago I asked how to process stacks using the > ParticleAnalyzer class. Here is the thread: > > > Imagej.1557.x6.nabble.com/ParticleAnalyzer-class-and-stacks-td5008596.html > > > > However, I did not solve it, and I apparently let it drop. Now I am > trying again. Here is a code snippet that get a stack, but only works > on the first slice. > > > > ######################## > > > > # set up the parameters for the particle analyzer > > minSize = 1 # pixels; We need to find a better basis for > setting a lower limit > > maxSize = width*height > > minCirc = 0.0 > > maxCirc = 1.0 > > options = > PA.SHOW_RESULTS+PA.EXCLUDE_EDGE_PARTICLES+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS > > > > measurements = Measurements.ALL_STATS > > rt = ResultsTable() > > > > pa = PA(options, measurements, rt, minSize, maxSize, minCirc, > maxCirc) > > print pa.processStack > > pa.analyze(lblImp, lblImp.getProcessor()) > > > > ######################## > > > > A few thins to note: > > > > 1. I set DOES_STACK. The PA code indicates that if this is done, and > the image is a stack, then the protected variable processStack will be > True. > > 2. I checked pa.processStack, and it is indeed True (pa is my > instance of the ParticleAnalyzer). > > 3. I checked the stack size of lblImp, and it is 11 (that is, > greater than 1) > > 4. I tried feeding pa.analyze an ImageStack - it did not want that > (cannot coerce to ImageProcessor) > > 5. I tried feeding pa.analyze the ImageProcessor, but that produces > the same result (only one mage processed). I tried giving it a > StackProcessor, > > but again, that cannot be coerced to an ImageProcessor. > > > > I ran the Particle Analyzer using the use interface to verify that > it runs on my image and can process the entire stack. > > > > I can loop through the ImageProcessors of the stack slices > (imageStack.getProcessor(n)), but it seems to me that the class is > capable of processing stacks, so my question is how? > > > > Thanks in advance > > --aryeh > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > . > -- 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 |
In reply to this post by Wayne Rasband-2
Hi Wayne and thank you for your reply.
On 28/08/2019 21:29, Wayne Rasband wrote: >> On Aug 28, 2019, at 4:18 AM, Aryeh Weiss <[hidden email]> wrote: >> >> More PA strangeness. In the test script just below this text, I expect to include Slice and Mode in my measurements. > The ParticleAnalyzer class does not process stacks. It is the IJ.run() method that runs the particle analyzer on all the images in a stack. An easy way to get the ROIs of all the particles in a stack is to run the particle analyzer using IJ.run(), have it create an overlay, retrieve the ROIs from the overlay and use ImagePlus.getStatistics (or ImagePlus.getAllStatistics) to get the desired measurements. The following JavaScript example does this: > > -wayne > > img = IJ.openImage("http://imagej.nih.gov/ij/images/t1-head.zip") > width = img.getWidth() > height = img.getHeight() > IJ.setRawThreshold(img, 50, 65535, "Red") > maxSize = width*height > options = "size=1-"+maxSize+" pixel show=Overlay clear stack" > IJ.run(img, "Analyze Particles...", options); > overlay = img.getOverlay() > for (i=0; i<overlay.size(); i++) { > roi = overlay.get(i) > img.setRoi(roi) > stats = img.getStatistics(); > slice = roi.getPosition(); > area = IJ.d2s(stats.area,2) > mode = stats.mode > print("roi="+i+", slice="+slice+", area="+area+", mode="+mode) > } I think that I can get all of the ROIs in each slice with one IJ.run command: IJ.run(imp, "Analyze Particles...", "size=1-Infinity pixel display clear add in_situ stack"); This produces an RoiManager with all of the detected objects. Best regards --aryeh >> I wrote the script as something minimal to see if I can get the PA class to work on the entire stack , or to demonstrate that it does not. >> Indeed it does not work on the entire stack, but in addition, Mode and Slice do not appear in the ResultsTable rt. This is strange because in my "large" script from which I took this code, I do get Mode and Slice. Also, even in the test script, rt.getColumnIndex("Mode") and rt.getColumnIndex("Slice") appear >> to return correct values for where those columns should be. When I run Analyze Particle from the GUI , all works as expected, Mode is in column 3 (Area is column 0), and Slice is in column 26 (my script says 27). So I am confused. Below is a script that should work on other installations, so maybe some of you can tell me if you get similar results. The output of the print statements is below the script. >> >> Thanks in advance >> --aryeh >> >> >> ################################################# >> ########### ParticleAnalyzer class test script################## >> >> from ij import IJ,ImagePlus >> from ij.plugin.filter import Analyzer, ParticleAnalyzer as PA >> from ij.plugin.frame import RoiManager >> from ij.measure import ResultsTable, Measurements >> from ij.process import ImageProcessor >> >> def testPA(imp): >> >> lblImp=imp.duplicate() >> >> width, height, nChannels, nSlices, nFrames = lblImp.getDimensions() >> >> IJ.setRawThreshold(lblImp, 50, 65535, "Red") >> lblImp.show() >> lblImp.setSlice(40) >> # set up the parameters for the particle analyzer >> minSize = 1 # pixels; We need to find a better basis for setting a lower limit >> maxSize = width*height # This is a weak upper bound. If the ROI is close to this, the segmentation is wrong >> minCirc = 0.0 >> maxCirc = 1.0 >> options = PA.SHOW_RESULTS+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS >> >> measurementsPA = Measurements.ALL_STATS+Measurements.STACK_POSITION+Measurements.SLICE+Measurements.MODE >> rt = ResultsTable() >> >> pa = PA(options, measurementsPA, rt, minSize, maxSize, minCirc, maxCirc) >> print "processStack = ", pa.processStack >> print "StackSize = ", lblImp.getStackSize() >> >> pa.analyze(lblImp) >> rm = RoiManager().getInstance() >> >> rt.updateResults() >> rt.show("Results") >> print "Area column index: ", rt.getColumnIndex("Area") >> print "Mode column index: ", rt.getColumnIndex("Mode") >> print "Slice column index: ", rt.getColumnIndex("Slice") >> areas = rt.getColumn(rt.getColumnIndex("Area")) >> means = rt.getColumn(rt.getColumnIndex("Mode")) >> slices = rt.getColumn(rt.getColumnIndex("Slice")) >> print slices, "\n", means, "\n", areas >> >> inputImp = IJ.openImage("http://imagej.nih.gov/ij/images/t1-head.zip") >> testPA(inputImp) >> >> ########### end of ParticleAnalyzer class test script############# >> ################################################ >> >> ##Script output: >> >> processStack = True >> StackSize = 129 >> Area column index: 0 >> Mode column index: 3 >> Slice column index: 27 >> None >> None >> array('f', [35586.0703125, 2.250004529953003, 6.75001335144043, 2.250004529953003, 2.250004529953003, 2.250004529953003, 2.250004529953003, 4.500009059906006, 78.75016021728516, 2.250004529953003, 11.250022888183594]) >> >> ## End of script output >> >> On 27/08/2019 12:20, Aryeh Weiss wrote: >>> Some years ago I asked how to process stacks using the ParticleAnalyzer class. Here is the thread: >>> Imagej.1557.x6.nabble.com/ParticleAnalyzer-class-and-stacks-td5008596.html >>> >>> However, I did not solve it, and I apparently let it drop. Now I am trying again. Here is a code snippet that get a stack, but only works on the first slice. >>> >>> ######################## >>> >>> # set up the parameters for the particle analyzer >>> minSize = 1 # pixels; We need to find a better basis for setting a lower limit >>> maxSize = width*height >>> minCirc = 0.0 >>> maxCirc = 1.0 >>> options = PA.SHOW_RESULTS+PA.EXCLUDE_EDGE_PARTICLES+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS >>> >>> measurements = Measurements.ALL_STATS >>> rt = ResultsTable() >>> >>> pa = PA(options, measurements, rt, minSize, maxSize, minCirc, maxCirc) >>> print pa.processStack >>> pa.analyze(lblImp, lblImp.getProcessor()) >>> >>> ######################## >>> >>> A few thins to note: >>> >>> 1. I set DOES_STACK. The PA code indicates that if this is done, and the image is a stack, then the protected variable processStack will be True. >>> 2. I checked pa.processStack, and it is indeed True (pa is my instance of the ParticleAnalyzer). >>> 3. I checked the stack size of lblImp, and it is 11 (that is, greater than 1) >>> 4. I tried feeding pa.analyze an ImageStack - it did not want that (cannot coerce to ImageProcessor) >>> 5. I tried feeding pa.analyze the ImageProcessor, but that produces the same result (only one mage processed). I tried giving it a StackProcessor, >>> but again, that cannot be coerced to an ImageProcessor. >>> >>> I ran the Particle Analyzer using the use interface to verify that it runs on my image and can process the entire stack. >>> >>> I can loop through the ImageProcessors of the stack slices (imageStack.getProcessor(n)), but it seems to me that the class is capable of processing stacks, so my question is how? >>> >>> Thanks in advance >>> --aryeh > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- 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 |
In reply to this post by Aryeh Weiss
Hi Aryeh,
if the ParticleAnalyzer runs as a PlugInFilter (i.e., if it called from the GUI, from a macro with 'run' or from Java/Javascript with 'IJ.run'), the DOES_STACKS flag tells the PluginFilterRunner to call the ParticleAnalyzers 'run' method for each stack slice. Since there is no 'PARALLELIZE_STACKS' flag, this is done sequentially, in a single thread. The flags for PlugInFilters are specified in https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/PlugInFilter.java There was no recent, relevant change of the ParticleAnalyzer that I could see on github. By the way, I think that the easiest for you would be to use IJ.run(imp, "Analyze Particles...", optionsString) If you have an ImageStack (which is probably in an ImagePlus anyhow), that would be easier than calling the ParticleAnalyzer for each slice, and it is less likely that problems would arise in case the internal workings of the ParticleAnalyzer should change in the future. Michael ___________________________________________________________________________ On 29/08/2019 7:50 AM, Aryeh Weiss wrote: > Hi Michael, > Thank you for your reply. > I wonder what DOES_STACKS is for. I thought maybe it was to allow the PA > to work on the selected slice, but that happens also without DOES_STACKS. > This morning, i ran my test script, and it threw an error saying that pa > has not attribute process.Stack. Yesterday it did not say this, and the > source and docs seem to have it. Has the source just been changed? > > Also, why does the ResultsTable does not show columns for Slice and > Mode in my test script. > > Note for the test script to run I now have to comment out > print pa.processStack > > Best regards, > --aryeh > > On 28/08/2019 20:58, Michael Schmid wrote: >> Hi Aryeh, >> >> when called from the GUI, a macro, or IJ.run, the ParticleAnalyzer >> processes stacks via the usual method of PlugInFilters, where the >> run(ip) method of the PlugInFilter is called for each slice of the >> stack (this is done by the PlugInFIlterRunner). If you create a new >> ParticleAnalyzer with the desired options and then call it analyze >> method, it will work only on the current stack slice. See the source >> code at: >> >> >> https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/ParticleAnalyzer.java#L429 >> >> >> You have to call it repeatedly for all slices (ImpagePlus.setSlice) if >> you want to analyze the whole stack. >> >> Michael >> ________________________________________________________________________ >> >> On 27/08/2019 11:20 AM, Aryeh Weiss wrote: >> > Some years ago I asked how to process stacks using the >> ParticleAnalyzer class. Here is the thread: >> > >> Imagej.1557.x6.nabble.com/ParticleAnalyzer-class-and-stacks-td5008596.html >> >> > >> > However, I did not solve it, and I apparently let it drop. Now I am >> trying again. Here is a code snippet that get a stack, but only works >> on the first slice. >> > >> > ######################## >> > >> > # set up the parameters for the particle analyzer >> > minSize = 1 # pixels; We need to find a better basis for >> setting a lower limit >> > maxSize = width*height >> > minCirc = 0.0 >> > maxCirc = 1.0 >> > options = >> PA.SHOW_RESULTS+PA.EXCLUDE_EDGE_PARTICLES+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS >> >> > >> > measurements = Measurements.ALL_STATS >> > rt = ResultsTable() >> > >> > pa = PA(options, measurements, rt, minSize, maxSize, minCirc, >> maxCirc) >> > print pa.processStack >> > pa.analyze(lblImp, lblImp.getProcessor()) >> > >> > ######################## >> > >> > A few thins to note: >> > >> > 1. I set DOES_STACK. The PA code indicates that if this is done, and >> the image is a stack, then the protected variable processStack will be >> True. >> > 2. I checked pa.processStack, and it is indeed True (pa is my >> instance of the ParticleAnalyzer). >> > 3. I checked the stack size of lblImp, and it is 11 (that is, >> greater than 1) >> > 4. I tried feeding pa.analyze an ImageStack - it did not want that >> (cannot coerce to ImageProcessor) >> > 5. I tried feeding pa.analyze the ImageProcessor, but that produces >> the same result (only one mage processed). I tried giving it a >> StackProcessor, >> > but again, that cannot be coerced to an ImageProcessor. >> > >> > I ran the Particle Analyzer using the use interface to verify that >> it runs on my image and can process the entire stack. >> > >> > I can loop through the ImageProcessors of the stack slices >> (imageStack.getProcessor(n)), but it seems to me that the class is >> capable of processing stacks, so my question is how? >> > >> > Thanks in advance >> > --aryeh >> > >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> . >> > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Michael.
Thank you for the explanation of that parameter. I still do not know why the ResultsTable in my test script does not have the Slice and Mode columns. I used IJ.run to run the particle analyzer, and it works as expected. My motivation for using the ParticleAnalyzer class was that in one of my scripts, when I ran the PA the script stopped, because the image remained locked. This happened sometimes, not always, so I assume this is also related to timing. Since I had in-situ show, when the RoiManager tried to make its overlay, the GUI displayed a line saying that the image was locked. I tried to reproduce this with a minimal script, where I ran the PA many times in a loop, but that worked perfectly. When I replaced the Ij.run() call with direct use of the PA class, this problem went away. Especially with methods that generate images, i try to use the API classes directly, and not through IJ.run. If an IJ.run command generates images, I need to know how they will be named and grab them. Also, if they generate images, they will display them, which I do not always need or want. If they display images, it maybe necessary to insert a loop that waits until the window is available. I should add that I started noticing these types of issues much more when I moved to a Lenovo X1 Xtreme, Ubuntu 19.04 (POP_OS) using a 4K display. Best regards --aryeh On 29/08/2019 18:17, Michael Schmid wrote: > Hi Aryeh, > > if the ParticleAnalyzer runs as a PlugInFilter (i.e., if it called > from the GUI, from a macro with 'run' or from Java/Javascript with > 'IJ.run'), the DOES_STACKS flag tells the PluginFilterRunner to call > the ParticleAnalyzers 'run' method for each stack slice. > > Since there is no 'PARALLELIZE_STACKS' flag, this is done > sequentially, in a single thread. > > The flags for PlugInFilters are specified in > https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/PlugInFilter.java > > > There was no recent, relevant change of the ParticleAnalyzer that I > could see on github. > > By the way, I think that the easiest for you would be to use > IJ.run(imp, "Analyze Particles...", optionsString) > > If you have an ImageStack (which is probably in an ImagePlus anyhow), > that would be easier than calling the ParticleAnalyzer for each slice, > and it is less likely that problems would arise in case the internal > workings of the ParticleAnalyzer should change in the future. > > Michael > ___________________________________________________________________________ > > > On 29/08/2019 7:50 AM, Aryeh Weiss wrote: >> Hi Michael, >> Thank you for your reply. >> I wonder what DOES_STACKS is for. I thought maybe it was to allow the >> PA to work on the selected slice, but that happens also without >> DOES_STACKS. >> This morning, i ran my test script, and it threw an error saying that >> pa has not attribute process.Stack. Yesterday it did not say this, >> and the source and docs seem to have it. Has the source just been >> changed? >> >> Also, why does the ResultsTable does not show columns for Slice and >> Mode in my test script. >> >> Note for the test script to run I now have to comment out >> print pa.processStack >> >> Best regards, >> --aryeh >> >> On 28/08/2019 20:58, Michael Schmid wrote: >>> Hi Aryeh, >>> >>> when called from the GUI, a macro, or IJ.run, the ParticleAnalyzer >>> processes stacks via the usual method of PlugInFilters, where the >>> run(ip) method of the PlugInFilter is called for each slice of the >>> stack (this is done by the PlugInFIlterRunner). If you create a new >>> ParticleAnalyzer with the desired options and then call it analyze >>> method, it will work only on the current stack slice. See the source >>> code at: >>> >>> >>> https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/ParticleAnalyzer.java#L429 >>> >>> >>> You have to call it repeatedly for all slices (ImpagePlus.setSlice) >>> if you want to analyze the whole stack. >>> >>> Michael >>> ________________________________________________________________________ >>> >>> >>> On 27/08/2019 11:20 AM, Aryeh Weiss wrote: >>> > Some years ago I asked how to process stacks using the >>> ParticleAnalyzer class. Here is the thread: >>> > >>> Imagej.1557.x6.nabble.com/ParticleAnalyzer-class-and-stacks-td5008596.html >>> >>> > >>> > However, I did not solve it, and I apparently let it drop. Now I >>> am trying again. Here is a code snippet that get a stack, but only >>> works on the first slice. >>> > >>> > ######################## >>> > >>> > # set up the parameters for the particle analyzer >>> > minSize = 1 # pixels; We need to find a better basis for >>> setting a lower limit >>> > maxSize = width*height >>> > minCirc = 0.0 >>> > maxCirc = 1.0 >>> > options = >>> PA.SHOW_RESULTS+PA.EXCLUDE_EDGE_PARTICLES+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS >>> >>> > >>> > measurements = Measurements.ALL_STATS >>> > rt = ResultsTable() >>> > >>> > pa = PA(options, measurements, rt, minSize, maxSize, minCirc, >>> maxCirc) >>> > print pa.processStack >>> > pa.analyze(lblImp, lblImp.getProcessor()) >>> > >>> > ######################## >>> > >>> > A few thins to note: >>> > >>> > 1. I set DOES_STACK. The PA code indicates that if this is done, >>> and the image is a stack, then the protected variable processStack >>> will be True. >>> > 2. I checked pa.processStack, and it is indeed True (pa is my >>> instance of the ParticleAnalyzer). >>> > 3. I checked the stack size of lblImp, and it is 11 (that is, >>> greater than 1) >>> > 4. I tried feeding pa.analyze an ImageStack - it did not want that >>> (cannot coerce to ImageProcessor) >>> > 5. I tried feeding pa.analyze the ImageProcessor, but that >>> produces the same result (only one mage processed). I tried giving >>> it a StackProcessor, >>> > but again, that cannot be coerced to an ImageProcessor. >>> > >>> > I ran the Particle Analyzer using the use interface to verify that >>> it runs on my image and can process the entire stack. >>> > >>> > I can loop through the ImageProcessors of the stack slices >>> (imageStack.getProcessor(n)), but it seems to me that the class is >>> capable of processing stacks, so my question is how? >>> > >>> > Thanks in advance >>> > --aryeh >>> > >>> >>> -- >>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>> . >>> >> > -- 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 |
Hi Aryeh,
there was a bug (introduced by me when preparing for the non-blocking dialogs for the filters - sorry) in one of the recent ImageJ versions, causing the ParticleAnalyzer to create an improper "locked image" error message. It should be fixed by now. In case you still see such a problem, let me know, please! Concerning images created by an IJ.run method: If there is only one image that is created, it usually becomes the foreground image (active image). Also, the last image created is that with the most negative ImageID. So if you have an IJ.run method creating only one image, you can use WindowManager.getIDList() and determine the most negative imageID. Then WindowManager.getImage(imageID) gives you a reference to the ImagePlus. Of course, neither of these approaches is safe in case of parallel operations due to multi-threading (but unfortunately, many ImageJ operations are not multithrading-safe, so running things in parallel is dangerous in much more respects) Michael ______________________________________________________________ On 29/08/2019 7:26 PM, Aryeh Weiss wrote: > Hi Michael. > > Thank you for the explanation of that parameter. I still do not know why > the ResultsTable in my test script does not have the Slice and Mode > columns. > > I used IJ.run to run the particle analyzer, and it works as expected. My > motivation for using the ParticleAnalyzer class was that in one of my > scripts, when I ran the PA the script stopped, because the image > remained locked. This happened sometimes, not always, so I assume this > is also related to timing. Since I had in-situ show, when the RoiManager > tried to make its overlay, the GUI displayed a line saying that the > image was locked. I tried to reproduce this with a minimal script, where > I ran the PA many times in a loop, but that worked perfectly. When I > replaced the Ij.run() call with direct use of the PA class, this problem > went away. > > Especially with methods that generate images, i try to use the API > classes directly, and not through IJ.run. If an IJ.run command generates > images, I need to know how they will be named and grab them. Also, if > they generate images, they will display them, which I do not always need > or want. If they display images, it maybe necessary to insert a loop > that waits until the window is available. > > I should add that I started noticing these types of issues much more > when I moved to a Lenovo X1 Xtreme, Ubuntu 19.04 (POP_OS) using a 4K > display. > > Best regards > --aryeh > > On 29/08/2019 18:17, Michael Schmid wrote: >> Hi Aryeh, >> >> if the ParticleAnalyzer runs as a PlugInFilter (i.e., if it called >> from the GUI, from a macro with 'run' or from Java/Javascript with >> 'IJ.run'), the DOES_STACKS flag tells the PluginFilterRunner to call >> the ParticleAnalyzers 'run' method for each stack slice. >> >> Since there is no 'PARALLELIZE_STACKS' flag, this is done >> sequentially, in a single thread. >> >> The flags for PlugInFilters are specified in >> https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/PlugInFilter.java >> >> >> There was no recent, relevant change of the ParticleAnalyzer that I >> could see on github. >> >> By the way, I think that the easiest for you would be to use >> IJ.run(imp, "Analyze Particles...", optionsString) >> >> If you have an ImageStack (which is probably in an ImagePlus anyhow), >> that would be easier than calling the ParticleAnalyzer for each slice, >> and it is less likely that problems would arise in case the internal >> workings of the ParticleAnalyzer should change in the future. >> >> Michael >> ___________________________________________________________________________ >> >> >> On 29/08/2019 7:50 AM, Aryeh Weiss wrote: >>> Hi Michael, >>> Thank you for your reply. >>> I wonder what DOES_STACKS is for. I thought maybe it was to allow the >>> PA to work on the selected slice, but that happens also without >>> DOES_STACKS. >>> This morning, i ran my test script, and it threw an error saying that >>> pa has not attribute process.Stack. Yesterday it did not say this, >>> and the source and docs seem to have it. Has the source just been >>> changed? >>> >>> Also, why does the ResultsTable does not show columns for Slice and >>> Mode in my test script. >>> >>> Note for the test script to run I now have to comment out >>> print pa.processStack >>> >>> Best regards, >>> --aryeh >>> >>> On 28/08/2019 20:58, Michael Schmid wrote: >>>> Hi Aryeh, >>>> >>>> when called from the GUI, a macro, or IJ.run, the ParticleAnalyzer >>>> processes stacks via the usual method of PlugInFilters, where the >>>> run(ip) method of the PlugInFilter is called for each slice of the >>>> stack (this is done by the PlugInFIlterRunner). If you create a new >>>> ParticleAnalyzer with the desired options and then call it analyze >>>> method, it will work only on the current stack slice. See the source >>>> code at: >>>> >>>> >>>> https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/ParticleAnalyzer.java#L429 >>>> >>>> >>>> You have to call it repeatedly for all slices (ImpagePlus.setSlice) >>>> if you want to analyze the whole stack. >>>> >>>> Michael >>>> ________________________________________________________________________ >>>> >>>> >>>> On 27/08/2019 11:20 AM, Aryeh Weiss wrote: >>>> > Some years ago I asked how to process stacks using the >>>> ParticleAnalyzer class. Here is the thread: >>>> > >>>> Imagej.1557.x6.nabble.com/ParticleAnalyzer-class-and-stacks-td5008596.html >>>> >>>> > >>>> > However, I did not solve it, and I apparently let it drop. Now I >>>> am trying again. Here is a code snippet that get a stack, but only >>>> works on the first slice. >>>> > >>>> > ######################## >>>> > >>>> > # set up the parameters for the particle analyzer >>>> > minSize = 1 # pixels; We need to find a better basis for >>>> setting a lower limit >>>> > maxSize = width*height >>>> > minCirc = 0.0 >>>> > maxCirc = 1.0 >>>> > options = >>>> PA.SHOW_RESULTS+PA.EXCLUDE_EDGE_PARTICLES+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS >>>> >>>> > >>>> > measurements = Measurements.ALL_STATS >>>> > rt = ResultsTable() >>>> > >>>> > pa = PA(options, measurements, rt, minSize, maxSize, minCirc, >>>> maxCirc) >>>> > print pa.processStack >>>> > pa.analyze(lblImp, lblImp.getProcessor()) >>>> > >>>> > ######################## >>>> > >>>> > A few thins to note: >>>> > >>>> > 1. I set DOES_STACK. The PA code indicates that if this is done, >>>> and the image is a stack, then the protected variable processStack >>>> will be True. >>>> > 2. I checked pa.processStack, and it is indeed True (pa is my >>>> instance of the ParticleAnalyzer). >>>> > 3. I checked the stack size of lblImp, and it is 11 (that is, >>>> greater than 1) >>>> > 4. I tried feeding pa.analyze an ImageStack - it did not want that >>>> (cannot coerce to ImageProcessor) >>>> > 5. I tried feeding pa.analyze the ImageProcessor, but that >>>> produces the same result (only one mage processed). I tried giving >>>> it a StackProcessor, >>>> > but again, that cannot be coerced to an ImageProcessor. >>>> > >>>> > I ran the Particle Analyzer using the use interface to verify that >>>> it runs on my image and can process the entire stack. >>>> > >>>> > I can loop through the ImageProcessors of the stack slices >>>> (imageStack.getProcessor(n)), but it seems to me that the class is >>>> capable of processing stacks, so my question is how? >>>> > >>>> > Thanks in advance >>>> > --aryeh >>>> > >>>> >>>> -- >>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>>> . >>>> >>> >> > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Michael
I am glad to hear that it is a known bug that was corrected. I will let you know if it recurs, but as I said, it was not consistently happening, so I do not know what triggered it. Concerning created images - generally, the operations that create such images create them with well defined names. Therefore, I wrote a function called getCreatedImage() that takes as its input the known title, and also a second string which is the title I want (if I do not want "C1 - xxxxxx" or whatever), and returns the imp, ip, and new image title. i will put it here for the benefit of anyone following this thread who may find it useful. def getCreatedImage(inputName, nameStr): # This function returns the ImagePlus, ImageProcessor, and image title associated # with an image that was opened with IJ.run(something that creates an image) # inputName is thename of the created image, and nameStr is what it will be renamed to. imp = WindowManager.getImage(inputName) imp.setTitle(nameStr) impTitle=imp.getTitle() ip = imp.getProcessor() return [imp, ip, impTitle] Some operations create more than one image, in which case this function will be called once for each created image. Also, one must be careful not to have two images with the same name. Best regards --aryeh On 29/08/2019 20:49, Michael Schmid wrote: > Hi Aryeh, > > there was a bug (introduced by me when preparing for the non-blocking > dialogs for the filters - sorry) in one of the recent ImageJ versions, > causing the ParticleAnalyzer to create an improper "locked image" > error message. It should be fixed by now. In case you still see such a > problem, let me know, please! > > Concerning images created by an IJ.run method: > If there is only one image that is created, it usually becomes the > foreground image (active image). > Also, the last image created is that with the most negative ImageID. > So if you have an IJ.run method creating only one image, you can use > WindowManager.getIDList() and determine the most negative imageID. > Then WindowManager.getImage(imageID) gives you a reference to the > ImagePlus. > Of course, neither of these approaches is safe in case of parallel > operations due to multi-threading (but unfortunately, many ImageJ > operations are not multithrading-safe, so running things in parallel > is dangerous in much more respects) > > Michael > ______________________________________________________________ > > > On 29/08/2019 7:26 PM, Aryeh Weiss wrote: >> Hi Michael. >> >> Thank you for the explanation of that parameter. I still do not know >> why the ResultsTable in my test script does not have the Slice and >> Mode columns. >> >> I used IJ.run to run the particle analyzer, and it works as expected. >> My motivation for using the ParticleAnalyzer class was that in one of >> my scripts, when I ran the PA the script stopped, because the image >> remained locked. This happened sometimes, not always, so I assume >> this is also related to timing. Since I had in-situ show, when the >> RoiManager tried to make its overlay, the GUI displayed a line saying >> that the image was locked. I tried to reproduce this with a minimal >> script, where I ran the PA many times in a loop, but that worked >> perfectly. When I replaced the Ij.run() call with direct use of the >> PA class, this problem went away. >> >> Especially with methods that generate images, i try to use the API >> classes directly, and not through IJ.run. If an IJ.run command >> generates images, I need to know how they will be named and grab >> them. Also, if they generate images, they will display them, which I >> do not always need or want. If they display images, it maybe >> necessary to insert a loop that waits until the window is available. >> >> I should add that I started noticing these types of issues much more >> when I moved to a Lenovo X1 Xtreme, Ubuntu 19.04 (POP_OS) using a 4K >> display. >> >> Best regards >> --aryeh >> >> On 29/08/2019 18:17, Michael Schmid wrote: >>> Hi Aryeh, >>> >>> if the ParticleAnalyzer runs as a PlugInFilter (i.e., if it called >>> from the GUI, from a macro with 'run' or from Java/Javascript with >>> 'IJ.run'), the DOES_STACKS flag tells the PluginFilterRunner to call >>> the ParticleAnalyzers 'run' method for each stack slice. >>> >>> Since there is no 'PARALLELIZE_STACKS' flag, this is done >>> sequentially, in a single thread. >>> >>> The flags for PlugInFilters are specified in >>> https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/PlugInFilter.java >>> >>> >>> There was no recent, relevant change of the ParticleAnalyzer that I >>> could see on github. >>> >>> By the way, I think that the easiest for you would be to use >>> IJ.run(imp, "Analyze Particles...", optionsString) >>> >>> If you have an ImageStack (which is probably in an ImagePlus >>> anyhow), that would be easier than calling the ParticleAnalyzer for >>> each slice, and it is less likely that problems would arise in case >>> the internal workings of the ParticleAnalyzer should change in the >>> future. >>> >>> Michael >>> ___________________________________________________________________________ >>> >>> >>> On 29/08/2019 7:50 AM, Aryeh Weiss wrote: >>>> Hi Michael, >>>> Thank you for your reply. >>>> I wonder what DOES_STACKS is for. I thought maybe it was to allow >>>> the PA to work on the selected slice, but that happens also without >>>> DOES_STACKS. >>>> This morning, i ran my test script, and it threw an error saying >>>> that pa has not attribute process.Stack. Yesterday it did not say >>>> this, and the source and docs seem to have it. Has the source just >>>> been changed? >>>> >>>> Also, why does the ResultsTable does not show columns for Slice >>>> and Mode in my test script. >>>> >>>> Note for the test script to run I now have to comment out >>>> print pa.processStack >>>> >>>> Best regards, >>>> --aryeh >>>> >>>> On 28/08/2019 20:58, Michael Schmid wrote: >>>>> Hi Aryeh, >>>>> >>>>> when called from the GUI, a macro, or IJ.run, the ParticleAnalyzer >>>>> processes stacks via the usual method of PlugInFilters, where the >>>>> run(ip) method of the PlugInFilter is called for each slice of the >>>>> stack (this is done by the PlugInFIlterRunner). If you create a >>>>> new ParticleAnalyzer with the desired options and then call it >>>>> analyze method, it will work only on the current stack slice. See >>>>> the source code at: >>>>> >>>>> >>>>> https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/ParticleAnalyzer.java#L429 >>>>> >>>>> >>>>> You have to call it repeatedly for all slices >>>>> (ImpagePlus.setSlice) if you want to analyze the whole stack. >>>>> >>>>> Michael >>>>> ________________________________________________________________________ >>>>> >>>>> >>>>> On 27/08/2019 11:20 AM, Aryeh Weiss wrote: >>>>> > Some years ago I asked how to process stacks using the >>>>> ParticleAnalyzer class. Here is the thread: >>>>> > >>>>> Imagej.1557.x6.nabble.com/ParticleAnalyzer-class-and-stacks-td5008596.html >>>>> >>>>> > >>>>> > However, I did not solve it, and I apparently let it drop. Now I >>>>> am trying again. Here is a code snippet that get a stack, but only >>>>> works on the first slice. >>>>> > >>>>> > ######################## >>>>> > >>>>> > # set up the parameters for the particle analyzer >>>>> > minSize = 1 # pixels; We need to find a better basis for >>>>> setting a lower limit >>>>> > maxSize = width*height >>>>> > minCirc = 0.0 >>>>> > maxCirc = 1.0 >>>>> > options = >>>>> PA.SHOW_RESULTS+PA.EXCLUDE_EDGE_PARTICLES+PA.CLEAR_WORKSHEET+PA.ADD_TO_MANAGER+PA.IN_SITU_SHOW+PA.DOES_STACKS >>>>> >>>>> > >>>>> > measurements = Measurements.ALL_STATS >>>>> > rt = ResultsTable() >>>>> > >>>>> > pa = PA(options, measurements, rt, minSize, maxSize, >>>>> minCirc, maxCirc) >>>>> > print pa.processStack >>>>> > pa.analyze(lblImp, lblImp.getProcessor()) >>>>> > >>>>> > ######################## >>>>> > >>>>> > A few thins to note: >>>>> > >>>>> > 1. I set DOES_STACK. The PA code indicates that if this is done, >>>>> and the image is a stack, then the protected variable processStack >>>>> will be True. >>>>> > 2. I checked pa.processStack, and it is indeed True (pa is my >>>>> instance of the ParticleAnalyzer). >>>>> > 3. I checked the stack size of lblImp, and it is 11 (that is, >>>>> greater than 1) >>>>> > 4. I tried feeding pa.analyze an ImageStack - it did not want >>>>> that (cannot coerce to ImageProcessor) >>>>> > 5. I tried feeding pa.analyze the ImageProcessor, but that >>>>> produces the same result (only one mage processed). I tried giving >>>>> it a StackProcessor, >>>>> > but again, that cannot be coerced to an ImageProcessor. >>>>> > >>>>> > I ran the Particle Analyzer using the use interface to verify >>>>> that it runs on my image and can process the entire stack. >>>>> > >>>>> > I can loop through the ImageProcessors of the stack slices >>>>> (imageStack.getProcessor(n)), but it seems to me that the class is >>>>> capable of processing stacks, so my question is how? >>>>> > >>>>> > Thanks in advance >>>>> > --aryeh >>>>> > >>>>> >>>>> -- >>>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>>>> . >>>>> >>>> >>> >> > -- 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 |
Free forum by Nabble | Edit this page |