-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBatchConvertNrrdsToJpgsRespectingFoldersCommandline.txt
72 lines (64 loc) · 2.03 KB
/
BatchConvertNrrdsToJpgsRespectingFoldersCommandline.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
64
65
66
67
68
69
70
71
72
// "BatchConvertStacksToZProjJPGS"
//
// This macro batch processes all the .bin.gz (ie IGS format) 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 file will have the name of the folder containing the "image.bin.gz" file
// along with the suffix .am
// ie some/image/path/image.bin.gz -> some/image/path.am
// (Slightly) Adapted by Greg Jefferis from code at
// http://rsb.info.nih.gov/ij/macros/BatchProcessFolders.txt
// jefferis@gmail.com
// v 0.1 2007-11-07
// - first version in response to a request from Jai
requires("1.33s");
dir = "/Volumes/JData/JPeople/Sebastian/fruitless/Registration/IS2Reg/ExtractedClones/" // getDirectory("Choose a stacks directory");
outputDir = "/Volumes/JData/JPeople/Sebastian/fruitless/Registration/IS2Reg/ExtractedClonesProjections/" // getDirectory("Choose output directory");
setBatchMode(true);
count = 0;
countFiles(dir);
print("Total files: "+count);
n = 0;
processFiles(dir, outputDir);
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,outputDir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/")){
if(File.exists(""+outputDir+list[i]) != 1){
File.makeDirectory(""+outputDir+list[i]);
}
processFiles(""+dir+list[i], ""+outputDir+list[i]);
} else {
showProgress(n++, count);
processFile(dir,outputDir,list[i]);
}
}
}
function processFile(dir,outputDir,file) {
if (endsWith(file,".nrrd")) {
newpath=outputDir+substring(file,0,lengthOf(file)-4)+"jpg";
if(File.exists(newpath)){
print("Skipping file: "+file+" since jpg already exists");
return;
}
path = dir+list[i];
open(path);
processImage();
saveAs("Jpeg", newpath);
close();
close();
}
}
function processImage() {
run("Z Project...", "projection=[Standard Deviation]");
run("8-bit");
}