-
Notifications
You must be signed in to change notification settings - Fork 1
/
SNR3View.ijm
109 lines (106 loc) · 3.15 KB
/
SNR3View.ijm
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Calculate signal-to-noise ratio for 3View images using
* Amira segmentation (segmented area = 2)
*/
macro "Calculate 3View SNR" {
if (nImages != 2) exit ("Exactly 2 images are required");
imgArray = newArray(nImages);
rowArray = newArray(nImages);
nZArray = newArray(nImages);
//print("\\Clear");
for (i=0; i<nImages; i++) {
selectImage(i+1);
imgArray[i] = getImageID();
title = getTitle();
rowArray[i] = title;
nZArray[i] = nSlices;
}
if (nZArray[0] != nZArray[1]) exit ("Not the same size");
numZ = nZArray[0];
Dialog.create("Prepare for analysis");
Dialog.addMessage("Which file is which?");
Dialog.addChoice("am file", rowArray);
Dialog.addChoice("3View TIFF", rowArray);
Dialog.show();
titleAm = Dialog.getChoice();
title3View = Dialog.getChoice();
// decisions collected
setBatchMode(true);
// threshold am
selectWindow(titleAm);
setAutoThreshold("Default dark");
setThreshold(1, 2);
setOption("BlackBackground", false);
// mask will not work from 8-bit color which some of the am files are
// bitDepth() == 8 in both cases.
run("8-bit"); // comment/uncomment if this is a problem.
run("Convert to Mask", "method=Default background=Dark");
// make large and medium version
// duplicate
run("Duplicate...", "title=med duplicate");
// dilate
selectWindow("med");
run("Dilate", "stack");
// duplicate that
run("Duplicate...", "title=large duplicate");
// dilate
selectWindow("large");
run("Dilate", "stack");
// dilate again
run("Dilate", "stack");
// make diff version, kill duplicates
imageCalculator("Subtract create stack", "large","med");
// selectWindow("Result of large");
selectWindow("large");
close();
selectWindow("med");
close();
// invert 3View
selectWindow(title3View);
run("Invert", "stack");
run("Set Scale...", "distance=0");
getDimensions(width, height, channels, slices, frames);
area = width * height;
// make tables to store data
tableTitle="[SNR data]";
if(isOpen("SNR data")) {
print(tableTitle, "\\Clear");
}
else {
run("Table...", "name="+tableTitle+" width=600 height=250");
print(tableTitle, "\\Headings:Slice\tMean\tStdev\tSNR\tArea1\tArea2");
}
run("Set Measurements...", "area mean standard redirect=" + title3View + " decimal=3");
// measure within original mask
for (i=0; i<numZ; i++) {
selectWindow(titleAm);
setSlice(i+1);
run("Create Selection");
run("Measure");
meanVar = getResult("Mean");
areaMeanVar = getResult("Area");
selectWindow("Result of large");
setSlice(i+1);
run("Create Selection");
run("Measure");
stdevVar = getResult("StdDev");
areaStdevVar = getResult("Area");
SNRVar = meanVar / stdevVar;
if ((areaMeanVar < 10 || areaMeanVar == area) || (areaStdevVar < 10 || areaStdevVar == area)) {
meanVar = NaN;
stdevVar = NaN;
SNRVar = NaN;
}
print(tableTitle, (i+1) + "\t" + meanVar + "\t" + stdevVar + "\t" + SNRVar + "\t" + areaMeanVar + "\t" + areaStdevVar);
}
selectWindow(title3View);
title = replace(title3View,".tif","");
dir = getInfo("image.directory");
run("Close All");
wait(1000);
call("java.lang.System.gc");
wait(1000);
selectWindow("SNR data");
saveAs("Text", dir+title+"SNR.txt");
setBatchMode(false);
}