-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_convert2tiff_allSeries_general_noSaturation.ijm
120 lines (104 loc) · 3.64 KB
/
batch_convert2tiff_allSeries_general_noSaturation.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
/* This script will batch-convert to .tif every .czi file in all subfolders of the folder you specify (interactively).
* Only the highest-resolution series (the first series and any other first ones if acquisition was split in several parts)
* will be converted.
* Images are saved as 8-bit.
*
* written by Paola Patella, PhD.
* FMI, Basel, March 2021
*/
run("Bio-Formats Macro Extensions");
setBatchMode(true);
dir = getDirectory("Choose a Directory ");
count = 0;
countFiles(dir);
print("files to process = " + count);
n = 0;
processFiles(dir);
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) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
processFiles(""+dir+list[i]);
else {
showProgress(n++, count);
path = dir+list[i];
processFile(path);
}
}
}
function processFile(path) {
if (endsWith(path, ".lif")) {
Ext.setId(path);
Ext.getSeriesCount(seriesCount); //zero-based
print("series count = " + seriesCount);
/*
Ext.getMetadataValue("Scaling|Distance|Value #1", value);
print(value);
value = 1000000*value;
appendingSt = "_" +value+ "umppx.tif";
seriesNumber = 1;
Ext.setSeries(0); //note that the index in this case is zero-based. This corresponds to series 1.
Ext.getSizeX(prevSizeX);
Ext.getSizeY(prevSizeY);
seriesLabel = "series_"+seriesNumber;
print("opening " + seriesLabel);
openingString = "open=" +path +" color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT " +seriesLabel;
//print(openingString);
run("Bio-Formats Importer", openingString);
saveTiff(path, seriesNumber, appendingSt);
*/
for (seriesNumber=1; seriesNumber<=seriesCount; seriesNumber++) {
//print(seriesNumber);
Ext.setSeries(seriesNumber-1);
/*
Ext.getSizeX(sizeX);
Ext.getSizeY(sizeY);
prevsz = prevSizeX*prevSizeY;
currsz = sizeX*sizeY;
*/
//print("previous squaresize: " +prevsz );
//print("current squaresize: " +currsz );
seriesLabel = "series_"+seriesNumber;
print("opening " + seriesLabel);
openingString = "open=[&path] color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT " +seriesLabel;
//print(openingString);
run("Bio-Formats Importer", openingString);
saveTiff(path, seriesNumber);
/*
if (prevsz < currsz) {
seriesLabel = "series_"+seriesNumber;
print("opening " + seriesLabel);
openingString = "open=[&path] color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT " +seriesLabel;
//print(openingString);
run("Bio-Formats Importer", openingString);
saveTiff(path, seriesNumber, appendingSt);
}
prevSizeX = sizeX;
prevSizeY = sizeY;
*/
}
}
}
function saveTiff(path, seriesNumber) {
getDimensions(width, height, channels, slices, frames);
// if it's a multi channel image
if (channels > 1) {
run("Split Channels");
run("Images to Stack", "name=Stack title=[] use");
}
run("8-bit");
filenameWrite = path+"_"+seriesNumber;
//print("series " +seriesNumber);
print("saving: " +filenameWrite);
saveAs("Tiff", filenameWrite);
close();
}