-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMake_MultiC_Stacks.ijm
executable file
·93 lines (71 loc) · 2.54 KB
/
Make_MultiC_Stacks.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Macro Make_MultiC_Stacks by Christophe Leterrier
// v1.0
// Takes an input folder containing single channel images
// Outputs a folder containing multi-channel tifs
// You must give an identifying string for each channel, and grouping will be done using what precedes this string in images names
macro "Make_MultiC_Stacks" {
// Get the folder name
inDir = getDirectory("Select a directory of single channel images");
print("\n\n\n*** Make MultiC Stacks Log ***");
print("input folder:" + inDir);
// Get name of input folder, parent folder, short name of input folder (before first space in name)
parDir = File.getParent(inDir);
inName = File.getName(inDir);
inShortA = split(inName, " ");
inShort = inShortA[0];
Id1_DEF = "561";
// Creation of the dialog box
Dialog.create("Make MultiC Stacks Options");
Dialog.addString("Id string for Channel #1", Id1_DEF);
Dialog.show();
// Feeding variables from dialog choices
Id1 = Dialog.getString();
// Create output folder
outDir = parDir + File.separator + inShort + " channels" + File.separator;
print("Output folder: " + outDir);
if (File.isDirectory(outDir) == false) {
File.makeDirectory(outDir);
}
setBatchMode(true);
// Count the number of files ending with ".tif" as the number of images
allNames = getFileList(inDir);
Array.sort(allNames);
imN = 0;
for (i = 0; i < allNames.length; i++) {
nLength = lengthOf(allNames[i]);
if (substring(allNames[i], nLength-4, nLength) == ".tif") {
imN ++;
}
}
print("Number of .tif images in input folder:" + imN);
// Store the images names in an array
imNames = newArray(imN);
for (i = 0; i < allNames.length; i++) {
nLength = lengthOf(allNames[i]);
if (substring(allNames[i], nLength-4, nLength) == ".tif") {
imNames[i] = allNames[i];
}
}
// Loop on images names
for (i = 0; i < imN; i++) {
// If image is first channel
C1 = lastIndexOf(imNames[i], Id1);
if (C1 > -1) {
fName = substring(imNames[i], 0, C1);
// Loop on all images in input folder to find all channels that share the same string BEFORE the channel ID string
for (j = 0; j < imN; j++) {
if (indexOf(imNames[j], fName) > -1) {
open(inDir + imNames[j]);
}
}
// at that point all channels should be open
run("Images to Stack", "name=Stack title=[] use");
run("Make Composite", "display=Composite");
save(outDir + fName + ".tif");
close();
} // end of if C1
} // end of loop in image names
setBatchMode("exit and display");
print("\n\n\n*** Make MultiC Stacks finished ***");
showStatus("Make MultiC Stacks finished");
}