File: Stack_Statistics.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 (54 lines) | stat: -rw-r--r-- 1,850 bytes parent folder | download | duplicates (3)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package ij.plugin;
import ij.*;
import ij.process.*;
import ij.plugin.filter.Analyzer;
import ij.measure.*;
import ij.gui.Roi;
import java.awt.Rectangle;

/** This plugin implements the Image/Stacks/Statistics command. */
public class Stack_Statistics implements PlugIn {
	
	public void run(String arg) {
		ImagePlus imp = IJ.getImage();
    	double histMax = imp.getBitDepth()==8||imp.getBitDepth()==24?256.0:0.0;
		int measurements = Analyzer.getMeasurements();
		Analyzer.setMeasurements(measurements | Measurements.LIMIT);
		ImageStatistics stats = new StackStatistics(imp, 256, 0.0, histMax);
		Analyzer.setMeasurements(measurements);
		ResultsTable rt = Analyzer.getResultsTable();
		rt.incrementCounter();
		Roi roi = imp.getRoi();
		if (roi!=null && !roi.isArea()) {
			imp.deleteRoi();
			roi = null;
		}
		double stackVoxels = 0.0;
		double images = imp.getStackSize();
		if (roi==null)
			stackVoxels = imp.getWidth()*imp.getHeight()*images;
		else if (roi.getType()==Roi.RECTANGLE) {
			Rectangle r = roi.getBounds();
			stackVoxels = r.width*r.height*images;
		} else {
			Analyzer.setMeasurements(measurements & ~Measurements.LIMIT);
			ImageStatistics stats2 = new StackStatistics(imp, 256, 0.0, histMax);
			Analyzer.setMeasurements(measurements);
			stackVoxels = stats2.longPixelCount;
		}
		Calibration cal = imp.getCalibration();
		String units = cal.getUnits();	
		double scale = cal.pixelWidth*cal.pixelHeight*cal.pixelDepth;
		rt.addValue("Voxels", stats.longPixelCount);
		if (scale!=1.0)
		rt.addValue("Volume("+units+"^3)", stats.longPixelCount*scale);
		rt.addValue("%Volume", stats.longPixelCount*100.0/stackVoxels);
		rt.addValue("Mean", stats.mean);
		rt.addValue("StdDev", stats.stdDev);
		rt.addValue("Min", stats.min);
		rt.addValue("Max", stats.max);
		rt.addValue("Mode", stats.dmode);
		rt.show("Results");
	}
	
}