-
Notifications
You must be signed in to change notification settings - Fork 2
/
BatchConvertNrrdToAmira.txt
63 lines (56 loc) · 1.47 KB
/
BatchConvertNrrdToAmira.txt
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
// "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, ".nrrd")) {
path = dir+file;
// Trim the terminal / from the dir
file=substring(file,0,lengthOf(file)-5);
// and construct a new path
newpath=dir+file+".am";
print("newpath ="+newpath);
// check if this already exists
if(!File.exists(newpath)){
// if not, process
open(path);
run("8-bit");
run("Amira Writer","amira=["+newpath+"]");
close();
}
}
}