Posted by
Aryeh Weiss on
Sep 18, 2013; 6:01am
URL: http://imagej.273.s1.nabble.com/Measure-without-displaying-results-tp5004809p5004842.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