1 package ij.plugin.filter;
3 import java.util.Vector;
4 import java.util.Properties;
10 import ij.plugin.MeasurementsWriter;
17 private ResultsTable rt;
18 private int measurements;
19 private StringBuffer min,max,mean,sd;
22 private static final int[] list = {AREA,MEAN,STD_DEV,MODE,MIN_MAX,
23 CENTROID,CENTER_OF_MASS,PERIMETER,RECT,ELLIPSE,CIRCULARITY, FERET,
24 LIMIT,LABELS,INVERT_Y};
26 private static final int UNDEFINED=0,AREAS=1,LENGTHS=2,ANGLES=3,MARK_AND_COUNT=4;
27 private static int mode = AREAS;
28 private static final String MEASUREMENTS =
"measurements";
29 private static final String MARK_WIDTH =
"mark.width";
30 private static final String PRECISION =
"precision";
32 private static boolean unsavedMeasurements;
33 public static Color darkBlue =
new Color(0,0,160);
34 private static int systemMeasurements =
Prefs.
getInt(MEASUREMENTS,AREA+MEAN+MIN_MAX);
35 public static int markWidth =
Prefs.
getInt(MARK_WIDTH,3);
36 public static int precision =
Prefs.
getInt(PRECISION,3);
38 private static ResultsTable systemRT =
new ResultsTable();
39 private static int redirectTarget;
40 private static String redirectTitle =
"";
41 static int firstParticle, lastParticle;
45 rt.setPrecision(precision);
46 measurements = systemMeasurements;
60 this.measurements = measurements;
68 if (arg.equals(
"sum"))
69 {summarize();
return DONE;}
70 else if (arg.equals(
"clear"))
71 {clearWorksheet();
return DONE;}
76 public void run(ij.process.ImageProcessor ip) {}
78 void clearWorksheet() {
82 void setOptions(GenericDialog gd) {
83 int oldMeasurements = systemMeasurements;
86 for (
int i=0; i<list.length; i++) {
88 b = gd.getNextBoolean();
91 systemMeasurements |= list[i];
93 systemMeasurements &= ~list[i];
95 if ((oldMeasurements&(~LIMIT))!=(systemMeasurements&(~LIMIT))) {
96 if (IJ.macroRunning()) {
102 if ((systemMeasurements&LABELS)==0)
103 systemRT.disableRowLabels();
109 double updateY(
double y) {
113 if ((systemMeasurements&INVERT_Y)!=0) {
115 y = imp.getHeight()*cal.pixelHeight-y;
123 double updateY2(
double y) {
127 if ((systemMeasurements&INVERT_Y)!=0) {
129 y = imp.getHeight()*cal.pixelHeight-y-cal.pixelHeight;
137 int counter = rt.getCounter();
140 IJ.
write(rt.getRowAsString(counter-1));
152 String tableHeadings = rt.getColumnHeadings();
153 if (worksheetHeadings.equals(tableHeadings))
156 int n = rt.getCounter();
158 StringBuffer sb =
new StringBuffer(n*tableHeadings.length());
159 for (
int i=0; i<
n; i++)
160 sb.append(rt.getRowAsString(i)+
"\n");
161 tp.
append(
new String(sb));
166 public String
n(
double n) {
168 if (Math.round(n)==
n)
171 s =
IJ.
d2s(n,precision);
175 void incrementCounter() {
177 if (rt==null) rt = systemRT;
178 rt.incrementCounter();
179 unsavedMeasurements =
true;
182 public void summarize() {
184 if (rt.getCounter()==0)
186 measurements = systemMeasurements;
187 min =
new StringBuffer(100);
188 max =
new StringBuffer(100);
189 mean =
new StringBuffer(100);
190 sd =
new StringBuffer(100);
193 mean.append(
"Mean\t");
195 if ((measurements&LABELS)!=0) {
201 if (mode==MARK_AND_COUNT)
203 else if (mode==LENGTHS)
204 add2(rt.getColumnIndex(
"Length"));
205 else if (mode==ANGLES)
206 add2(rt.getColumnIndex(
"Angle"));
211 String worksheetHeadings = tp.getColumnHeadings();
212 if (worksheetHeadings.equals(
""))
216 IJ.write(
new String(mean));
217 IJ.write(
new String(sd));
218 IJ.write(
new String(min));
219 IJ.write(
new String(max));
227 void summarizePoints(ResultsTable rt) {
228 add2(rt.getColumnIndex(
"X"));
229 add2(rt.getColumnIndex(
"Y"));
230 add2(rt.getColumnIndex(
"Value"));
233 void summarizeAreas() {
234 if ((measurements&AREA)!=0) add2(ResultsTable.AREA);
235 if ((measurements&MEAN)!=0) add2(ResultsTable.MEAN);
236 if ((measurements&STD_DEV)!=0) add2(ResultsTable.STD_DEV);
237 if ((measurements&MODE)!=0) add2(ResultsTable.MODE);
238 if ((measurements&MIN_MAX)!=0) {
239 add2(ResultsTable.MIN);
240 add2(ResultsTable.MAX);
242 if ((measurements&CENTROID)!=0) {
243 add2(ResultsTable.X_CENTROID);
244 add2(ResultsTable.Y_CENTROID);
246 if ((measurements&CENTER_OF_MASS)!=0) {
247 add2(ResultsTable.X_CENTER_OF_MASS);
248 add2(ResultsTable.Y_CENTER_OF_MASS);
250 if ((measurements&PERIMETER)!=0)
251 add2(ResultsTable.PERIMETER);
252 if ((measurements&RECT)!=0) {
253 add2(ResultsTable.ROI_X);
254 add2(ResultsTable.ROI_Y);
255 add2(ResultsTable.ROI_WIDTH);
256 add2(ResultsTable.ROI_HEIGHT);
258 if ((measurements&ELLIPSE)!=0) {
259 add2(ResultsTable.MAJOR);
260 add2(ResultsTable.MINOR);
261 add2(ResultsTable.ANGLE);
263 if ((measurements&CIRCULARITY)!=0)
264 add2(ResultsTable.CIRCULARITY);
265 if ((measurements&FERET)!=0)
266 add2(ResultsTable.FERET);
269 private void add2(
int column) {
270 float[] c = column>=0?rt.getColumn(column):null;
272 ImageProcessor ip =
new FloatProcessor(c.length, 1, c, null);
275 ImageStatistics stats =
new FloatStatistics(ip);
278 mean.append(
n(stats.mean));
279 min.append(
n(stats.min));
280 max.append(
n(stats.max));
281 sd.append(
n(stats.stdDev));
292 return systemRT.getCounter();
301 int counter = systemRT.getCounter();
304 if (counter>0 && lineCount>0 && unsavedMeasurements && !
IJ.macroRunning() && ij!=null) {
305 SaveChangesDialog d =
new SaveChangesDialog(ij,
"Save "+counter+
" measurements?");
306 if (d.cancelPressed())
308 else if (d.savePressed())
313 unsavedMeasurements =
false;
321 public static void setSaved() {
322 unsavedMeasurements =
false;
326 public static int getMeasurements() {
327 return systemMeasurements;
331 public static void setMeasurements(
int measurements) {
332 systemMeasurements = measurements;
337 prefs.put(MEASUREMENTS, Integer.toString(systemMeasurements));
338 prefs.put(MARK_WIDTH, Integer.toString(markWidth));
339 prefs.put(PRECISION, Integer.toString(precision)); }
358 public static int updateY(
int y,
int imageHeight) {
359 if ((systemMeasurements&INVERT_Y)!=0)