-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplit 2 channels Zstacks_v1.0.ijm
67 lines (55 loc) · 2.06 KB
/
Split 2 channels Zstacks_v1.0.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
// -------------------------------------------------------------------
// Written by: Patrice Mascalchi
// Date: 2020-02
// DRVision Technologies LLC
// -------------------------------------------------------------------
// **** manual parameters ****
nCh = 2;
// ********************************
// Get image directory ---------------
path = getDirectory("Choose the directory containing your files");
flist = SortFileList(path, ".tif");
if (!endsWith(path, File.separator)) path = path + File.separator;
// Get name of selected folder
tmp = File.getParent(path);
parentDir = substring(path, lengthOf(tmp)+1);
if (!endsWith(parentDir, File.separator)) parentDir = parentDir + File.separator;
if (lengthOf(parentDir) > 20) parentDir = substring(parentDir, 0, 20);
// Defining output directory
outdirs = newArray(nCh);
for (o=0; o<nCh; o++) {
outdirs[o] = path + "C" + o+1 + "-" + parentDir;
if (!File.exists(outdirs[o])) File.makeDirectory(outdirs[o]);
}
setBatchMode(true);
// Processing the files
for (f=0; f<flist.length; f++) {
fname = flist[f];
// run("Bio-Formats Importer", "open=[" + path + flist[f] +"] autoscale color_mode=Composite view=Hyperstack stack_order=Default);
open(path + fname);
print("Processing "+ f+1 +"/"+ flist.length +": "+ fname);
nSl = nSlices / nCh;
run("Stack to Hyperstack...", "order=xyczt(default) channels="+nCh+" slices="+nSl+" frames=1 display=Color");
run("Split Channels");
for (c=1; c<=nCh; c++) {
selectWindow("C"+ c +"-"+ fname);
saveAs(outdirs[c-1] +"C"+ c +"-"+ fname);
}
run("Close All");
}
setBatchMode(false);
print("Done!");
// --------------------------------------------------
function SortFileList(path, filter) { // Sort with endsWith
flist = getFileList(path);
OutAr = newArray(flist.length);
ind = 0;
for (f=0; f<flist.length; f++) {
//print(flist[f] + " : "+endsWith(flist[f], filter));
if (endsWith(flist[f], filter)) {
OutAr[ind] = flist[f];
ind++;
}
}
return Array.trim(OutAr, ind);
}