Posted by
Rasband, Wayne (NIH/NIMH) [E] on
URL: http://imagej.273.s1.nabble.com/Adding-a-measurement-type-tp5005620p5005627.html
On Nov 20, 2013, at 10:00 AM, Grant Harris wrote:
> I'd like to add a measurement for circular/directional statistics for calculating the average orientation of an area/ROI.
> I'd like to do this so that I can utilize the functionality of the RoiManager and the ResultsTable, e.g. select a number of ROIs, do the measurement, and have the results in a table. Does anyone have an idea on how to do this?
Have you considered using the "Fit ellipse" measurement option to get ROI orientation? It adds "Major", "Minor" and "Angle" columns to the Results table. Here is an example macro that draws the ellipse major axis on each particle in the Blobs sample image:
saveSettings;
open("
http://imagej.nih.gov/ij/images/blobs.gif");
setAutoThreshold("Default");
run("Set Measurements...", " centroid fit");
run("Analyze Particles...", "exclude clear");
resetThreshold();
setColor("red");
setLineWidth(2);
for (i=0; i<nResults; i++) {
xc = getResult("X", i);
yc = getResult("Y", i);
major = getResult("Major", i);
angle = getResult("Angle", i);
dx = major*cos(angle/180 * PI)/2;
dy = -major * sin(angle/180 * PI)/2;
x1 = xc - dx;
x2 = xc + dx;
y1 = yc - dy;
y2 = yc + dy;
Overlay.drawLine(x1, y1, x2, y2);
}
Overlay.show;
restoreSettings;
And here is a JavaScript version:
imp = IJ.openImage("
http://imagej.nih.gov/ij/images/blobs.gif");
Analyzer.setMeasurement(Measurements.CENTROID, true);
Analyzer.setMeasurement(Measurements.ELLIPSE, true);
IJ.setAutoThreshold(imp, "Default");
IJ.run(imp, "Analyze Particles...", "exclude clear");
IJ.resetThreshold(imp);
rt = Analyzer.getResultsTable();
overlay = new Overlay();
for (i=0; i<rt.getCounter(); i++) {
xc = rt.getValue("X", i);
yc = rt.getValue("Y", i);
major = rt.getValue("Major", i);
angle = rt.getValue("Angle", i);
dx = major*Math.cos(angle/180 * Math.PI)/2;
dy = -major * Math.sin(angle/180 * Math.PI)/2;
x1 = xc - dx;
x2 = xc + dx;
y1 = yc - dy;
y2 = yc + dy;
line = new Line(x1, y1, x2, y2);
line.setStrokeColor(Color.red);
line.setStrokeWidth(2);
overlay.add(line);
}
imp.setOverlay(overlay);
imp.show();
[cid:
[hidden email]]
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html