-
Notifications
You must be signed in to change notification settings - Fork 0
/
backgroundSubtract.ijm
58 lines (44 loc) · 1.55 KB
/
backgroundSubtract.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
// subtract the background
// Close all open tif's
close("*.tif");
// Define the folder with files
// root folder
folder = getDirectory("Select a Directory for import");
setBatchMode(true);
medianRad = 10; // size of the median filter
// only 3 first channels are considered
for(j = 0; j < 3; j++){
channelInput = folder + "channels/c" + (j + 1) + "/"; // this is the folder for each channel
medianInput = folder + "median/c" + (j + 1) + "/"; // this is the folder for each channel
channelOutput = folder+ "subtracted/c" + (j + 1) + "/";
cFilenames = getFileList(channelInput);
mFilenames = getFileList(medianInput);
// might be useless
Array.sort(cFilenames);
Array.sort(mFilenames);
for (i = 0; i < cFilenames.length; i++){
// work only on the tif files in the input folders
if (endsWith(cFilenames[i], ".tif")){
// show which file we are processing
// print(cFilenames[i]);
// progress bar
showProgress(i + 1, cFilenames.length);
icFile = channelInput + cFilenames[i]; // path
imFile = medianInput + mFilenames[i]; // path
print(icFile);
print(imFile);
open(icFile);
// initial images are 16-bit
run("32-bit");
open(imFile);
imageCalculator("Subtract create 32-bit stack", cFilenames[i], mFilenames[i]);
Stack.getStatistics(voxelCount, mean, min, max, stdDev);
run("Add...", "value=" + (-1*min) + " stack");
ocFile = channelOutput + cFilenames[i];
saveAs("Tiff", substring(ocFile, 0, lengthOf(ocFile) - 4));
// Close all open tif's
close("*.tif");
}
}
}
print("DOGE!");