-
Notifications
You must be signed in to change notification settings - Fork 2
/
BatchStackregTiffs.ijm
57 lines (51 loc) · 1.66 KB
/
BatchStackregTiffs.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
// "BatchSmoothTifToAmira"
//
// This macro batch processes all the tif files
// in a folder and any subfolders in that folder.
// It then saves them in the Amiramesh format using the Amira_Writer plugin
// The new filename will end in smooth.am
// (Slightly) Adapted by Greg Jefferis from code at
// http://rsb.info.nih.gov/ij/macros/BatchProcessFolders.txt
requires("1.33s");
dir = getDirectory("Choose a Directory ");
setBatchMode(true);
count = 0;
countFiles(dir);
n = 0;
processFiles(dir);
//print(count+" files processed");
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) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
processFiles(""+dir+list[i]);
else {
showProgress(n++, count);
//path = dir+list[i];
processFile(dir,list[i]);
}
}
}
function processFile(dir,file) {
if (endsWith(file, ".tif") && !endsWith(file, "-stackreg.tif")) {
path = dir+file;
open(path);
newpath=replace(path,".tif","-stackreg.tif");
run("Stack to Hyperstack...", "order=xyztc channels=1 slices=7 frames=16 display=Color");
run("Re-order Hyperstack ...", "channels=[Channels (c)] slices=[Frames (t)] frames=[Slices (z)]");
run("StackReg", "transformation=Translation");
run("Re-order Hyperstack ...", "channels=[Channels (c)] slices=[Frames (t)] frames=[Slices (z)]");
saveAs("Tiff", newpath);
close();
}
}