-
Notifications
You must be signed in to change notification settings - Fork 0
/
bioformats-split-positions.ijm
131 lines (118 loc) · 3.41 KB
/
bioformats-split-positions.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
inputFolder = getDirectory("Choose the folder containing images to process:");
// Create an output folder based on the inputFolder
parentFolder = getPath(inputFolder); inputFolderPrefix = getPathFilenamePrefix(inputFolder);
outputFolder = parentFolder + inputFolderPrefix + "-splitPositions" + File.separator;
if ( !(File.exists(outputFolder)) ) { File.makeDirectory(outputFolder); }
run("Close All");
setBatchMode(true);
flist = getFileList(inputFolder);
for (i=0; i<flist.length; i++) {
filename = inputFolder + flist[i];
filenamePrefix = getFilenamePrefix(flist[i]);
if ( endsWith(filename, ".nd") || endsWith(filename, ".nd2") || endsWith(filename, ".czi") ) {
run("Bio-Formats Macro Extensions");
Ext.setId(filename); Ext.getSeriesCount(seriesCount);
print(seriesCount);
for(seriesNum = 0; seriesNum < seriesCount; seriesNum++) {
Ext.setSeries(seriesNum);
Ext.openImagePlus(filename);
N_temp = zeroPadding(seriesNum, seriesCount);
save(outputFolder + filenamePrefix + "-" + N_temp + ".tif");
}
run("Close All");
}
}
function getPathFilenamePrefix(pathFileOrFolder) {
// this one takes full path of the file
temp = split(pathFileOrFolder, File.separator);
temp = temp[temp.length-1];
temp = split(temp, ".");
return temp[0];
}
function getFilenamePrefix(filename) {
// this one takes just the file name without folder path
temp = split(filename, ".");
return temp[0];
}
function getPath(pathFileOrFolder) {
// this one takes full path of the file (input can also be a folder) and returns the parent folder path
temp = split(pathFileOrFolder, File.separator);
if ( File.separator == "/" ) {
// Mac and unix system
pathTemp = File.separator;
for (i=0; i<temp.length-1; i++) {pathTemp = pathTemp + temp[i] + File.separator;}
}
if ( File.separator == "\\" ) {
// Windows system
pathTemp = temp[0] + File.separator;
for (i=1; i<temp.length-1; i++) {pathTemp = pathTemp + temp[i] + File.separator;}
}
return pathTemp;
}
function zeroPadding(N, N_max) {
if ( N_max < 10 ) {
temp = toString(N); return temp;
}
if ( N_max < 100 ) {
temp = zeroPadding2(N); return temp;
}
if ( N_max < 1000 ) {
temp = zeroPadding3(N); return temp;
}
if ( N_max < 10000 ) {
temp = zeroPadding4(N); return temp;
}
else {
print( "Warning! Maximum >= 10000! Change zeroPadding to account for that.");
temp = toString(N);
return temp;
}
}
function zeroPadding4(t) {
// pad t to 4 digits when t <1000
if ( t < 10 ) {
tPadded = "000" + t; return tPadded;
}
if ( t < 100 ) {
tPadded = "00" + t; return tPadded;
}
if ( t < 1000 ) {
tPadded = "0" + t; return tPadded;
}
if ( t < 10000 ) {
temp = toString(t); return temp;
}
else {
print( "Warning! Maximum >= 10000! Change zeroPadding to account for that.");
temp = toString(t); return temp;
}
}
function zeroPadding3(t) {
// pad t to 4 digits when t <1000
if ( t < 10 ) {
tPadded = "00" + t; return tPadded;
}
if ( t < 100 ) {
tPadded = "0" + t; return tPadded;
}
if ( t < 1000 ) {
temp = toString(t); return temp;
}
else {
print( "Warning! Maximum >= 1000! Change zeroPadding to account for that.");
temp = toString(t); return temp;
}
}
function zeroPadding2(t) {
// pad t to 4 digits when t <1000
if ( t < 10 ) {
tPadded = "0" + t; return tPadded;
}
if ( t < 100 ) {
temp = toString(t); return temp;
}
else {
print( "Warning! Maximum >= 100! Change zeroPadding to account for that.");
temp = toString(t); return temp;
}
}