-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_Measure.java
More file actions
91 lines (86 loc) · 2.34 KB
/
Copy pathStack_Measure.java
File metadata and controls
91 lines (86 loc) · 2.34 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package HomeMade.Tools;
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;
import ij.IJ;
import ij.measure.ResultsTable;
import java.util.Arrays;
public class Stack_Measure implements PlugIn {
int [] Dim;
ResultsTable rt = ResultsTable.getResultsTable();
ResultsTable ResT= ResultsTable.getResultsTable();
double [][] Res;
int Slices,a,b,c,d,e,f,sliceN,numobj,counter;
Roi cRoi;
RoiManager rm;
ImagePlus imp;
public void run(String arg) {
if (arg==""){
arg="Default ResultTable";
}
if (imp==null){
imp = IJ.getImage(); //get image
}
Dim=imp.getDimensions(); //get dimensions
Slices=Dim[2]*Dim[3]*Dim[4]; //calculate number of images Dim[2]=channels, Dim[3]=stacks, Dim[4]=frames
if (rm==null){
rm = RoiManager.getInstance(); //get Roimanager
}
if (rm!=null){
numobj=rm.getCount(); //get number of rois in roimanager
} else {
cRoi = imp.getRoi();
if (cRoi!=null){
numobj=1;
} else {
numobj=1;
}
}
Res=new double[numobj][Slices]; //create result array
IJ.run("Set Measurements...", "mean redirect=None decimal=2"); // set measurments
counter=0;
for (c=0;c<Dim[2];c++){ //loop trough channels
for (a=0;a<Dim[4];a++){ //loop through time
for (b=0;b<Dim[3];b++){ //loop through stack
for (d=0;d<numobj;d++){ //loop through d
IJ.run("Clear Results", "");
sliceN= (b*Dim[2]+a*Dim[2]*Dim[3]+c+1);//determine slice number to be measured
if (rm!=null){
rm.select(d); //needs to go before set slice otherwise the slice where the roi was set will be measured
} else if (cRoi!=null){
imp.setRoi(cRoi);
} else {
IJ.run(imp, "Select All", "");
}
imp.setSlice(sliceN);//set slice
IJ.run(imp, "Measure", "");//measure
Res[d][counter]=rt.getValue("Mean",0); //get result in resultarray
}
counter=counter+1;
}
}
}
ResT=new ResultsTable();
for (f=0;f<Slices;f++){
ResT.incrementCounter();
for (e=0;e<numobj;e++){
ResT.addValue(""+e,Res[e][f]);
ResT.show(arg);
}
}
}
public Stack_Measure(ImagePlus imp, RoiManager roiM){
this.imp =imp;
this.rm=roiM;
run("Roi Manager results");
}
public Stack_Measure(ImagePlus imp){
this.imp =imp;
run("Image input");
}
public Stack_Measure(){ // needed to start the run in stand alone version
}
}