-
Notifications
You must be signed in to change notification settings - Fork 1
/
ometotiff_with_stitching.ijm
159 lines (136 loc) · 4.42 KB
/
ometotiff_with_stitching.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
setBatchMode( true );
//parametry_konwersji
remove = false;
n_remove = 1;
//parametry_stitchingu
overlap=20;
//start_script
input = getDirectory("Input directory");
output = input+"/tifs/";
if (File.exists(output)!=1) {
print("Tworzę folder: " + output);
File.makeDirectory(output);
}
//open dialog to let user ddefine the grid
Dialog.create("Number of tiles");
Dialog.addString("x= ", "1", 2);
Dialog.addString("y= ", "2", 2);
Dialog.show();
x = Dialog.getString();
y = Dialog.getString();
xInt=parseInt(x);
yInt=parseInt(y);
ile=xInt*yInt;
//ome to tif
suffix_raw = ".ome.tif";
processFolderOmetotiff(input, suffix_raw);
//prepare stitching
suffix = ".tif";
suff_ii="{ii}";
number_ii=lengthOf(suff_ii)-2;
ileplikow = 0;
input=output;
nazwa = processFolderCountfiles(input, suffix);
print("Znaleziono plikow: "+ileplikow);
if(ile>ileplikow)
print("Za malo plikow do stitchingu!");
else {
print("Prawidłowa liczba plikow");
v = newArray(0,0,0);
v = getSizes(input);
unit = "µm";
print("after getSizes "+ unit +" "+ v[0] +" "+ v[1] +" "+ v[2]);
nazwaPliku=nazwa+suff_ii;
print("Nazwa pliku bedzie taka: "+nazwaPliku);
setBatchMode( false );
type = "type=[Grid: column-by-column] order=[Down & Right ]"; //kamera Hamamatsu
grid_size = " grid_size_x="+x+" grid_size_y="+y;
file_names = " file_names="+nazwaPliku+suffix;
dir=" directory="+input;
rest=" output_textfile_name=TileConfig.txt fusion_method=[Linear Blending] regression_threshold=0.30 max/avg_displacement_threshold=2.50 absolute_displacement_threshold=3.50 compute_overlap display_fusion computation_parameters=[Save memory (but be slower)] image_output=[Fuse and display]";
restdisk=" output_textfile_name=TileConfig.txt fusion_method=[Linear Blending] regression_threshold=0.30 max/avg_displacement_threshold=2.50 absolute_displacement_threshold=3.50 compute_overlap display_fusion computation_parameters=[Save memory (but be slower)] image_output=[Write to disk]";
params = type+grid_size+" tile_overlap="+overlap+" first_file_index_i=0"+dir+file_names+rest;
run("Grid/Collection stitching", params);
setVoxelSize(v[0], v[1], v[2], unit);
}
/////////////////////////////////////////////////////////////////////////////////
//funkcje
function linearizeNameString(namestring) {
stala="Pos_";
poz1=indexOf(namestring, stala)+lengthOf(stala);
poz2=poz1+4;
nazwa=substring(namestring, 0, poz1);
print(nazwa);
valX=parseInt(substring(namestring, poz1, poz2-1));
print(valX);
valY=parseInt(substring(namestring, poz2, lengthOf(namestring)));
print(valY);
}
function parseNameString(namestring) {
stala="Pos_";
ext=".ome"
poz1=indexOf(namestring, stala)+lengthOf(stala);
poz2=indexOf(namestring, ext)
nazwa=substring(namestring, 0, poz1);
print(nazwa);
valX=parseInt(substring(namestring, poz1, poz2-1));
print(valX);
valY=parseInt(substring(namestring, poz2, lengthOf(namestring)));
print(valY);
}
function processFolderOmetotiff(input, suffix_in) {
list = getFileList(input);
ileplikow = 0;
//print("Przetwarzam katalog "+input);
folderstring=substring(input,0,lengthOf(input)-1);
folderstring=substring(folderstring, lastIndexOf(folderstring, "\\")+1, lengthOf(folderstring));
for (i = 0; i < list.length; i++) {
if(endsWith(list[i], suffix_in)) {
ileplikow++;
namestring=substring(list[i], 0, indexOf(list[i], "MMStack"));
indx=substring(list[i], indexOf(list[i], "_Pos")+4, indexOf(list[i], suffix_in));
print(indx);
processFileOmetotiff(input+list[i], output+namestring+indx+".tif");
}
}
print("Koniec "+ input + " ! Przetworzono plikow "+ileplikow);
//print("koniec testu");
}
function processFileOmetotiff(input_file, output_file) {
// do the processing here
open(input_file);
if(remove) {
run("Slice Remover", "first=1 last=n_remove increment=1");
}
saveAs("Tiff", output_file);
close();
print("Zapisano: " + output_file);
print("");
}
function processFolderCountfiles(input, suffix) {
list = getFileList(input);
brak_nazwy=1;
for (i = 0; i < list.length; i++) {
if(endsWith(list[i], suffix)) {
if(brak_nazwy) {
nazwa=substring(list[i], 0, indexOf(list[i], suffix)-number_ii);
brak_nazwy=0;
}
ileplikow++;
}
}
return nazwa;
}
function getSizes(input) {
list = getFileList(input);
print("Trying to find dimensions of: "+input+list[0]);
open(input+list[0], "virtual");
vw=0;
vh=0;
vd=0;
unit="";
getVoxelSize(vw, vh, vd, unit);
v = newArray(vw, vh, vd);
close(list[0]);
return v;
}