-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchImageProcessingSMT.ijm
156 lines (114 loc) · 3.72 KB
/
BatchImageProcessingSMT.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
macro "ImageProcessingSMT"{
//Set folder
input_dir = getDirectory("Choose directory");
output_dir = input_dir;
//Get file list
filelist = getFileList(input_dir);
//Set parameters
Dialog.create("Parameters");
Dialog.addCheckbox("Subtract BG",true);
Dialog.addNumber("SB",25,0,8,"pix");
Dialog.addNumber("BC_Min",0,0,8,"tone");
Dialog.addNumber("BC_Max",1200,0,8,"tone");
Dialog.addCheckbox("Run. Avg.",true);
Dialog.addNumber("Running",2,0,8,"frames");
Dialog.addCheckbox("Save tif",true);
Dialog.addCheckbox("Save avi",true);
Dialog.addNumber("FrameRate",33,1,8,"fps");
Dialog.show();
SBflag = Dialog.getCheckbox();
SB = Dialog.getNumber();
BC_Min = Dialog.getNumber();
BC_Max = Dialog.getNumber();
RAflag = Dialog.getCheckbox();
RunAvg = Dialog.getNumber();
SaveTif = Dialog.getCheckbox();
SaveAvi = Dialog.getCheckbox();
FrameRate = Dialog.getNumber();
//Batch processing
for (i=0; i<filelist.length; i++) {
if(SBflag == 1){
output_file = filelist[i]+"_SB"+SB+"_BC"+BC_Min+"-"+BC_Max+"_"+FrameRate+"fps.avi";
}else{
output_file = filelist[i]+"_BC"+BC_Min+"-"+BC_Max+"_"+FrameRate+"fps.avi";
}
output_path = output_dir+output_file;
open(input_dir + filelist[i]);
//run("Delete Slice");
if(SBflag == 1){
run("Subtract Background...", "rolling=SB stack");
}
if(RAflag == 1){
run("Running ZProjector", "running=RunAvg projection=[Average Intensity]");
selectWindow(filelist[i]);
close();
selectWindow(filelist[i]+"-RunAv(2)");
}
run("Brightness/Contrast...");
setMinAndMax(BC_Min, BC_Max);
if(SaveTif == 1){
saveAs("Tiff", output_path);
}
if(SaveAvi == 1){
run("AVI... ", "compression=Uncompressed frame=FrameRate save=[output_path]");
}
close();
}
}
macro "Split2ch"{
//Set Folder
input_dir = getDirectory("Choose directory");
output_dir = input_dir;
//Get File list
filelist = getFileList(input_dir);
//Batch processing
for (i=0; i<filelist.length; i++) {
output_file = filelist[i]+"-ch1.tif";
output_path = output_dir+output_file;
open(input_dir + filelist[i]);
run("Specify...", "width=512 height=512 x=0 y=0 slice=1");
run("Crop");
saveAs("Tiff", output_path);
close();
output_file = filelist[i]+"-ch2.tif";
output_path = output_dir+output_file;
open(input_dir + filelist[i]);
run("Specify...", "width=512 height=512 x=512 y=0 slice=1");
run("Crop");
saveAs("Tiff", output_path);
close();
}
}
macro "Composite2ch"{
//Set Folder
input_dir = getDirectory("Choose directory");
output_dir = input_dir;
input_ch1 = input_dir+"\C1\\";
input_ch2 = input_dir+"\C2\\";
//Get file lists from C1 and C2 folders
filelist1 = getFileList(input_ch1);
filelist2 = getFileList(input_ch2);
NumImage = filelist1.length;
//Batch processing
for (i=0; i<NumImage; i=i+1) {
filename1 = filelist1[i];
filename2 = filelist2[i];
output_file_avi = filename1+"_composite.avi";
output_file_tif = filename1+"_composite.tif";
output_path_avi = output_dir+output_file_avi;
output_path_tif = output_dir+output_file_tif;
open(input_ch1 + filelist1[i]);
selectWindow(filename1);
//run("Brightness/Contrast...");
//setMinAndMax(0, 800);
open(input_ch2 + filelist2[i]);
selectWindow(filename2);
//run("Brightness/Contrast...");
//setMinAndMax(0, 800);
run("Merge Channels...", "red=[" + filename2 + "] green=[" + filename1 + "] create");
selectWindow("Composite");
//run("AVI... ", "compression=Uncompressed frame=33.3 save=[output_path_avi]"); //Activate this line if you want to save avi files.
saveAs("Tiff", output_path_tif);
close();
}
}