File: BatchMeasure.java

package info (click to toggle)
imagej 1.52j-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,604 kB
  • sloc: java: 120,017; sh: 279; xml: 161; makefile: 6
file content (32 lines) | stat: -rw-r--r-- 966 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package ij.plugin;
import ij.*;
import ij.measure.Measurements;
import ij.plugin.filter.Analyzer;
import java.io.*;

/** This plugin implements the File/Batch/Measure command, 
	which measures all the images in a user-specified folder. */
	public class BatchMeasure implements PlugIn {

	public void run(String arg) {
		String dir = IJ.getDirectory("Choose a Folder");
		if (dir==null) return;
		String[] list = (new File(dir)).list();
		if (list==null) return;
		Analyzer.setMeasurement(Measurements.LABELS, true);
		for (int i=0; i<list.length; i++) {
			if (list[i].startsWith(".")) continue;
			String path = dir + list[i];
			IJ.showProgress(i+1, list.length);
			IJ.redirectErrorMessages(true);
			ImagePlus imp = !path.endsWith("/")?IJ.openImage(path):null;
			IJ.redirectErrorMessages(false);
			if (imp!=null) {
				IJ.run(imp, "Measure", "");
				imp.close();
			} else if (!path.endsWith("/"))
				IJ.log("IJ.openImage() returned null: "+path);
		}
	}

}