Dear all,
In an automation routine with a Clojure macro, I use a loop over all objects in an image with "DoWand", "Convex Hull" and then "Measure", so that I can get the convex perimeter of each object, calculate the Convexity, and then get the average Convexity from all objects in the field. However, the "Measure" command always displays the results in the standard output port, what creates an unnecessary delay in the routine. The "Analyze Particles" does have the "Display" option, but "Measure" apparently does not have such an option. I have actually used "Analyze Particles" instead of "Measure" (iterating over the objects) but that is much slower still. Is there a way to suppress the results display in "Measure"? Is there a lower level command I could use to replace "Measure" in such a Clojure macro? For that matter, is there such a lower level command for "Set Measurements" and/or "Analyze Particles"? Thank you! Prof. Sidnei Paciornik Grupo de Análise de Imagens e Microscopia Digital DEMa <http://www.dema.puc-rio.br/> - Departamento de Engenharia de Materiais PUC-Rio <http://www.puc-rio.br/> Rua Marquês de São Vicente 225 Prédio Leme, Sala 501L Gávea - Rio de Janeiro - RJ 22451-900 - Brasil tel: (55)(21)3527-1243 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Sep 16, 2013, at 2:21 PM, Sidnei Paciornik wrote:
> Dear all, > > In an automation routine with a Clojure macro, I use a loop over all > objects in an image with "DoWand", "Convex Hull" and then "Measure", so > that I can get the convex perimeter of each object, calculate the > Convexity, and then get the average Convexity from all objects in the field. > > However, the "Measure" command always displays the results in the standard > output port, what creates an unnecessary delay in the routine. The "Analyze > Particles" does have the "Display" option, but "Measure" apparently does > not have such an option. I have actually used "Analyze Particles" instead > of "Measure" (iterating over the objects) but that is much slower still. > > Is there a way to suppress the results display in "Measure"? > Is there a lower level command I could use to replace "Measure" in such a > Clojure macro? > For that matter, is there such a lower level command for "Set Measurements" > and/or "Analyze Particles"? Use the Analyzer class. Specify the measurements when you call the constructor and call the measure() method to make measurements. Here is a JavaScript example. -wayne imp = IJ.createImage("Untitled", "8-bit ramp", 500, 500, 1); measurements = Measurements.AREA; measurements += Measurements.MEAN; measurements += Measurements.PERIMETER; measurements += Measurements.SHAPE_DESCRIPTORS; rt = new ResultsTable(); analyzer = new Analyzer(imp, measurements, rt); analyzer.measure(); xpoints = [318,359,371,409,385]; ypoints = [51,21,65,26,113]; poly = new Polygon(xpoints, ypoints, xpoints.length); imp.setRoi(new PolygonRoi(poly,Roi.POLYGON)); analyzer.measure(); IJ.run(imp, "Convex Hull", ""); analyzer.measure(); rt.show("Results"); -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On 9/18/13 7:57 AM, Rasband, Wayne (NIH/NIMH) [E] wrote:
> > Use the Analyzer class. Specify the measurements when you call the constructor and call the measure() method to make measurements. Here is a JavaScript example. > > -wayne > > imp = IJ.createImage("Untitled", "8-bit ramp", 500, 500, 1); > measurements = Measurements.AREA; > measurements += Measurements.MEAN; > measurements += Measurements.PERIMETER; > measurements += Measurements.SHAPE_DESCRIPTORS; > rt = new ResultsTable(); > analyzer = new Analyzer(imp, measurements, rt); > analyzer.measure(); > xpoints = [318,359,371,409,385]; > ypoints = [51,21,65,26,113]; > poly = new Polygon(xpoints, ypoints, xpoints.length); > imp.setRoi(new PolygonRoi(poly,Roi.POLYGON)); > analyzer.measure(); > IJ.run(imp, "Convex Hull", ""); > analyzer.measure(); > rt.show("Results"); > When I tried to run this, I had the following error: Started New_.js at Wed Sep 18 07:52:57 IST 2013 org.mozilla.javascript.EcmaError: ReferenceError: "Polygon" is not defined. (New_.js#13) So I tried the following simple js which I recorded: imp = IJ.openImage("http://imagej.nih.gov/ij/images/AuPbSn40.jpg"); xpoints = [171,250,375,84,86]; ypoints = [197,101,248,286,285]; imp.setRoi(new PolygonRoi(xpoints,ypoints,5,Roi.POLYGON)); imp.show(); but then it returned an error: org.mozilla.javascript.EvaluatorException: The choice of Java method ij.gui.PolygonRoi.ij.gui.PolygonRoi matching JavaScript argument types (object,object,number,number) is ambiguous; candidate methods are: PolygonRoi(float[],float[],int,int) PolygonRoi(int[],int[],int,int) (Script.js#4) Recording this same set of operations as a java program produces: import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.*; import ij.plugin.frame.*; public class My_Plugin implements PlugIn { public void run(String arg) { ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/AuPbSn40.jpg"); int[] xpoints = {211,358,409,213,208}; int[] ypoints = {202,105,235,292,296}; imp.setRoi(new PolygonRoi(xpoints,ypoints,5,Roi.POLYGON)); imp.show(); } } and this works correctly I use the Fiji distribution, and am running these from the script editor. --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 Sep 18, 2013, at 2:01 AM, Aryeh Weiss wrote:
> On 9/18/13 7:57 AM, Rasband, Wayne (NIH/NIMH) [E] wrote: >> >> Use the Analyzer class. Specify the measurements when you call the constructor and call the measure() method to make measurements. Here is a JavaScript example. >> >> -wayne >> >> imp = IJ.createImage("Untitled", "8-bit ramp", 500, 500, 1); >> measurements = Measurements.AREA; >> measurements += Measurements.MEAN; >> measurements += Measurements.PERIMETER; >> measurements += Measurements.SHAPE_DESCRIPTORS; >> rt = new ResultsTable(); >> analyzer = new Analyzer(imp, measurements, rt); >> analyzer.measure(); >> xpoints = [318,359,371,409,385]; >> ypoints = [51,21,65,26,113]; >> poly = new Polygon(xpoints, ypoints, xpoints.length); >> imp.setRoi(new PolygonRoi(poly,Roi.POLYGON)); >> analyzer.measure(); >> IJ.run(imp, "Convex Hull", ""); >> analyzer.measure(); >> rt.show("Results"); >> > > When I tried to run this, I had the following error: > Started New_.js at Wed Sep 18 07:52:57 IST 2013 > org.mozilla.javascript.EcmaError: ReferenceError: "Polygon" is not defined. (New_.js#13) You can work around this error by adding importClass(java.awt.Polygon); to the script. The JavaScript interpreter in ImageJ includes more classes by default than the one in Fiji. There is a list of the included classes at http://imagej.nih.gov/ij/developer/javascript.html > So I tried the following simple js which I recorded: > > imp = IJ.openImage("http://imagej.nih.gov/ij/images/AuPbSn40.jpg"); > xpoints = [171,250,375,84,86]; > ypoints = [197,101,248,286,285]; > imp.setRoi(new PolygonRoi(xpoints,ypoints,5,Roi.POLYGON)); > imp.show(); > > but then it returned an error: > > org.mozilla.javascript.EvaluatorException: The choice of Java method ij.gui.PolygonRoi.ij.gui.PolygonRoi matching JavaScript argument types (object,object,number,number) is ambiguous; candidate methods are: > PolygonRoi(float[],float[],int,int) > PolygonRoi(int[],int[],int,int) (Script.js#4) This is a stupid bug in the Rhino JavaScript interpreter that is included with Java. It should just choose the more general the two PolygonRoi constructors, the one that accepts float arrays. The latest ImageJ daily build (1.48d4) works around this bug by adding a PolygonRoi(float[],float[],int) constructor, which is now used by the Recorder. With the daily build, the recorded code is now imp = IJ.openImage("http://imagej.nih.gov/ij/images/AuPbSn40.jpg"); xpoints = [171,250,375,84,86]; ypoints = [197,101,248,286,285]; imp.setRoi(new PolygonRoi(xpoints,ypoints,Roi.POLYGON)); imp.show(); Example code like this that opens a sample image now runs much faster, and also runs offline, if you first cache the sample images using the new File>Open Samples>Cache Sample Images command. -wayne > Recording this same set of operations as a java program produces: > import ij.*; > import ij.process.*; > import ij.gui.*; > import java.awt.*; > import ij.plugin.*; > import ij.plugin.frame.*; > > public class My_Plugin implements PlugIn { > > public void run(String arg) { > ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/AuPbSn40.jpg"); > int[] xpoints = {211,358,409,213,208}; > int[] ypoints = {202,105,235,292,296}; > imp.setRoi(new PolygonRoi(xpoints,ypoints,5,Roi.POLYGON)); > imp.show(); > } > > } > > and this works correctly > > I use the Fiji distribution, and am running these from the script editor. > > --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 |
Thank you Wayne! I will try it out.
Regards, Prof. Sidnei Paciornik Grupo de Análise de Imagens e Microscopia Digital DEMa <http://www.dema.puc-rio.br/> - Departamento de Engenharia de Materiais PUC-Rio <http://www.puc-rio.br/> Rua Marquês de São Vicente 225 Prédio Leme, Sala 501L Gávea - Rio de Janeiro - RJ 22451-900 - Brasil tel: (55)(21)3527-1243 On Wed, Sep 18, 2013 at 3:37 PM, Rasband, Wayne (NIH/NIMH) [E] < [hidden email]> wrote: > On Sep 18, 2013, at 2:01 AM, Aryeh Weiss wrote: > > > On 9/18/13 7:57 AM, Rasband, Wayne (NIH/NIMH) [E] wrote: > >> > >> Use the Analyzer class. Specify the measurements when you call the > constructor and call the measure() method to make measurements. Here is a > JavaScript example. > >> > >> -wayne > >> > >> imp = IJ.createImage("Untitled", "8-bit ramp", 500, 500, 1); > >> measurements = Measurements.AREA; > >> measurements += Measurements.MEAN; > >> measurements += Measurements.PERIMETER; > >> measurements += Measurements.SHAPE_DESCRIPTORS; > >> rt = new ResultsTable(); > >> analyzer = new Analyzer(imp, measurements, rt); > >> analyzer.measure(); > >> xpoints = [318,359,371,409,385]; > >> ypoints = [51,21,65,26,113]; > >> poly = new Polygon(xpoints, ypoints, xpoints.length); > >> imp.setRoi(new PolygonRoi(poly,Roi.POLYGON)); > >> analyzer.measure(); > >> IJ.run(imp, "Convex Hull", ""); > >> analyzer.measure(); > >> rt.show("Results"); > >> > > > > When I tried to run this, I had the following error: > > Started New_.js at Wed Sep 18 07:52:57 IST 2013 > > org.mozilla.javascript.EcmaError: ReferenceError: "Polygon" is not > defined. (New_.js#13) > > You can work around this error by adding > > importClass(java.awt.Polygon); > > to the script. The JavaScript interpreter in ImageJ includes more classes > by default than the one in Fiji. There is a list of the included classes at > > http://imagej.nih.gov/ij/developer/javascript.html > > > So I tried the following simple js which I recorded: > > > > imp = IJ.openImage("http://imagej.nih.gov/ij/images/AuPbSn40.jpg"); > > xpoints = [171,250,375,84,86]; > > ypoints = [197,101,248,286,285]; > > imp.setRoi(new PolygonRoi(xpoints,ypoints,5,Roi.POLYGON)); > > imp.show(); > > > > but then it returned an error: > > > > org.mozilla.javascript.EvaluatorException: The choice of Java method > ij.gui.PolygonRoi.ij.gui.PolygonRoi matching JavaScript argument types > (object,object,number,number) is ambiguous; candidate methods are: > > PolygonRoi(float[],float[],int,int) > > PolygonRoi(int[],int[],int,int) (Script.js#4) > > This is a stupid bug in the Rhino JavaScript interpreter that is included > with Java. It should just choose the more general the two PolygonRoi > constructors, the one that accepts float arrays. The latest ImageJ daily > build (1.48d4) works around this bug by adding a > PolygonRoi(float[],float[],int) constructor, which is now used by the > Recorder. > > With the daily build, the recorded code is now > > imp = IJ.openImage("http://imagej.nih.gov/ij/images/AuPbSn40.jpg"); > xpoints = [171,250,375,84,86]; > ypoints = [197,101,248,286,285]; > imp.setRoi(new PolygonRoi(xpoints,ypoints,Roi.POLYGON)); > imp.show(); > > Example code like this that opens a sample image now runs much faster, and > also runs offline, if you first cache the sample images using the new > File>Open Samples>Cache Sample Images command. > > -wayne > > > > Recording this same set of operations as a java program produces: > > import ij.*; > > import ij.process.*; > > import ij.gui.*; > > import java.awt.*; > > import ij.plugin.*; > > import ij.plugin.frame.*; > > > > public class My_Plugin implements PlugIn { > > > > public void run(String arg) { > > ImagePlus imp = IJ.openImage(" > http://imagej.nih.gov/ij/images/AuPbSn40.jpg"); > > int[] xpoints = {211,358,409,213,208}; > > int[] ypoints = {202,105,235,292,296}; > > imp.setRoi(new PolygonRoi(xpoints,ypoints,5,Roi.POLYGON)); > > imp.show(); > > } > > > > } > > > > and this works correctly > > > > I use the Fiji distribution, and am running these from the script editor. > > > > --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 > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |