-
Notifications
You must be signed in to change notification settings - Fork 2
/
FRC-QE_automated_macro.ijm
163 lines (134 loc) · 5.14 KB
/
FRC-QE_automated_macro.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//by Friedrich Preusser (github.com/Fritze/)
//August 2020
//For this macro to work it needs the "BigStitcher" update site to be activated.
//This macro will automatically perform FRC-QE on multiple 3D images.
//Steps happening here:
// 1. You select a folder that contains all your images. All files within this folder should be images.
// 2. Enter your FFT size (i.e. FRC block size). This should be helt constant when comparing images.
// 3. If you want to also calculate Shannon Entropy, please select the corresponding button.
// 3. A results folder will be created for each image individually (folder has the name of the image).
// 4. The macro will perform FRC-QE and Shannon entropy measurements (if selected) for all images and save the results as csv. file in the results folder.
// 5. A message will show up when all images have been processed.
setBatchMode(true);
dir = getDirectory("Choose a Directory ");
count = 0;
n = 0;
list = getFileList(dir);
number_of_files = list.length;
Dialog.create("FRC-QE macro");
Dialog.addNumber("Enter the FFT size (i.e. FRC block size) you want to use for all images that will be processed.", 200);
Dialog.addCheckbox("Should Shannon entropy be calculated?", true);
Dialog.addCheckbox("Should average intensity be calculated?", true);
Dialog.show();
FFT_size = Dialog.getNumber();
entropy = Dialog.getCheckbox();
intensity = Dialog.getCheckbox();
processFiles(dir);
function countFiles(dir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
countFiles(""+dir+list[i]);
else
count++;
}
}
function processFiles(dir) {
for (i=0; i<number_of_files; i++) {
path = dir+list[i];
if (!matches(list[i], ".*/.*")) {
processFile(path);
}
}
Dialog.create("DONE.");
Dialog.addMessage("All images were processed.");
Dialog.show();
}
function processFile(path) {
name = File.getName(path);
dotIndex = indexOf(name, ".");
name = substring(name, 0, dotIndex);
// print the file name
print("Now processing :", name);
// open the file
open(path);
directory = File.getParent(path)+"/";
title = getTitle();
// FRC calculation
selectWindow(title);
run("FRC-QE: 3D Image Quality Estimation", "quality_method=[relative FRC (Fourier Ring Correlation)] area_for_quality=[Entire image] fft_size=" + FFT_size + " step_size=1 relative_frc_distance=10");
close();
//create results folder
results_folder_path = directory + "/" + name + "/";
File.makeDirectory(results_folder_path);
// name of the image and csv generated is set here
path_file = results_folder_path+"FRC_"+name+".csv";
// Save as csv file
Table.rename("Image Quality (rFRC)", "Results");
saveAs("Results", path_file);
close("Results");
run("Clear Results");
if (entropy) {
// Shannon Entropy
selectWindow(title);
run("FRC-QE: 3D Image Quality Estimation", "quality_method=[Shannon Entropy] area_for_quality=[Entire image]");
close();
// name of the image and csv generated is set here
path_file = results_folder_path+"Shannon-entropy_"+name+".csv";
// Save as csv file
Table.rename("Image Quality (Shannon Entropy)", "Results");
saveAs("Results", path_file);
close("Results");
run("Clear Results");
// DCT Shannon Entropy
selectWindow(title);
run("FRC-QE: 3D Image Quality Estimation", "quality_method=[Normalized DCT Shannon Entropy] area_for_quality=[Entire image]");
close();
// name of the image and csv generated is set here
path_file = results_folder_path+"DCT-Shannon-entropy_"+name+".csv";
// Save as csv file
Table.rename("Image Quality (DCT Shannon Entropy)", "Results");
saveAs("Results", path_file);
close("Results");
run("Clear Results");
// median DCT Shannon Entropy
selectWindow(title);
run("FRC-QE: 3D Image Quality Estimation", "quality_method=[Normalized DCT Shannon Entropy, median filtered] area_for_quality=[Entire image]");
close();
// name of the image and csv generated is set here
path_file = results_folder_path+"median-DCT-Shannon-entropy_"+name+".csv";
// Save as csv file
Table.rename("Image Quality (median DCT Shannon Entropy)", "Results");
saveAs("Results", path_file);
close("Results");
run("Clear Results");
// DFT Shannon Entropy
selectWindow(title);
run("FRC-QE: 3D Image Quality Estimation", "quality_method=[Normalized DFT Shannon Entropy] area_for_quality=[Entire image]");
close();
// name of the image and csv generated is set here
path_file = results_folder_path+"DFT-Shannon-entropy_"+name+".csv";
// Save as csv file
Table.rename("Image Quality (DFT Shannon Entropy)", "Results");
saveAs("Results", path_file);
close("Results");
run("Clear Results");
}
if (intensity) {
selectWindow(title);
run("Set Measurements...", "mean min stack display invert redirect=None decimal=3");
for (n=1; n<=nSlices; n++) {
setSlice(n);
run("Measure");
}
updateResults;
// name of the image and csv generated is set here
path_file = results_folder_path+"Img-features_"+name+".csv";
// Save as csv file
saveAs("Results", path_file);
close("Results");
run("Clear Results");
}
close(title);
print(title + " was processed.");
}