-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveAllChannelCombinations.ijm
103 lines (83 loc) · 2.73 KB
/
SaveAllChannelCombinations.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
94
95
96
97
98
99
100
101
102
103
// Save all possible channel combinations to PNGs
// Export all possible channel combinations to PNGs in the same directory as
// the original stack. Only works with single slices for now. Filenames should
// not have spaces.
// TODO: Make it work with Z-stacks
// TODO: Deal with spaces in file name
// Get stack path and name
path = getDirectory("image");
stackname = getTitle();
// Define a basename
basename = File.getNameWithoutExtension(stackname);
rename(basename);
// Use the basename to create a directory
outdir = path + basename + File.separator;
File.makeDirectory(outdir);
// Get stack dimensions
Stack.getDimensions(width, height, channels, slices, frames);
// Save PNG with all channels for cover
run("RGB Color");
saveAs("png", path + basename + ".png");
// Save another all channels PNG for directory
allchannels = basename + "_C1234"
saveAs("png", outdir + allchannels + ".png");
// Close PNG with all channels
close();
// Split channels
selectWindow(basename);
run("Duplicate...", "title=split duplicate");
run("Split Channels");
// Create and save every channel combination
for (i=1; i<=channels; i++) {
//print(i);
// Save single channels using the gray LUT
selectWindow(basename);
grayed = basename + "_C" + i;
run("Duplicate...", "title=" + grayed + " duplicate channels=" + i);
run("Grays");
// Convert to RGB for general use
run("RGB Color");
// Save as PNG
saveAs("png", outdir + grayed + ".png");
print(grayed);
// Close grayscale image
close(grayed);
for (j=i+1; j<=channels; j++) {
//print(i, j);
// Merge two channels keeping original files
run("Merge Channels...", "c1=C" + i + "-split c2=C" + j +"-split create keep");
// Define name for combined stack
combined = basename + "_C" + toString(i) + toString(j);
rename(combined);
// Convert to RGB for general use
run("RGB Color");
// Save as PNG
saveAs("png", outdir + combined + ".png");
// Close combined TIF
print(combined);
close(combined);
for (k=i+2; k<=channels; k++) {
//print(i, j, k);
// Skip to avoid repeated combinations
if (k<=j) {
continue;
}
// Merge three channels keeping original files
run("Merge Channels...", "c1=C" + i + "-split c2=C" + j + "-split c3=C" + k + "-split create keep");
// Define name for combined stack
combined = basename + "_C" + toString(i) + toString(j) + toString(k);
rename(combined);
// Convert to RGB for general use
run("RGB Color");
// Save as PNG
saveAs("png", outdir + combined + ".png");
// Close combined TIF
print(combined);
close(combined);
}
}
}
// Make stack and montage for inspection
open(outdir + allchannels + ".png");
run("Images to Stack", "use");
run("Make Montage...", "columns=" + channels + " rows=" + channels + 1 + " scale=1");