forked from PolusAI/argolid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
268 lines (237 loc) · 11.6 KB
/
main.cpp
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include <iostream>
#include <string>
#include "../src/ome_tiff_to_chunked_converter.h"
#include "../src/pyramid_view.h"
#include "../src/chunked_pyramid_assembler.h"
#include "../src/chunked_base_to_pyr_gen.h"
#include "../src/ome_tiff_to_chunked_pyramid.h"
#include "../src/utilities.h"
#include "BS_thread_pool.hpp"
#include<chrono>
#include "tensorstore/tensorstore.h"
#include "tensorstore/context.h"
#include "tensorstore/array.h"
#include "tensorstore/driver/zarr/dtype.h"
#include "tensorstore/index_space/dim_expression.h"
#include "tensorstore/kvstore/kvstore.h"
#include "tensorstore/open.h"
using namespace argolid;
/*
void test_zarr_pyramid_writer(){
std::string input_file = "/home/samee/Downloads/WT_Uninfected_top_right.tif";
std::string output_file = "/home/samee/axle/data/bia_test";
//input_file = "/home/samee/axle/data/test_image.ome.tif";
//output_file = "/home/samee/axle/data/test_image_ome_zarr_2";
auto zpw = OmeTiffToChunkedConverter();
auto t1 = std::chrono::high_resolution_clock::now();
BS::thread_pool<BS::tp::none> th_pool;
zpw.Convert(input_file, output_file, "16", VisType::Viv ,th_pool);
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> et1 = t2-t1;
std::cout << "time for base image: "<< et1.count() << std::endl;
}
void test_zarr_pyramid_assembler()
{
std::string input_dir = "/home/samee/axle/data/intensity1";
std::string output_file = "/home/samee/axle/data/test_assembly";
std::string stitch_vector = "/home/samee/axle/data/tmp_dir/img-global-positions-1.txt";
auto zpw = OmeTiffCollToChunked();
auto t1 = std::chrono::high_resolution_clock::now();
BS::thread_pool<BS::tp::none> th_pool;
zpw.Assemble(input_dir, stitch_vector, output_file, "17", VisType::PCNG, th_pool);
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> et1 = t2-t1;
std::cout << "time for base image: "<< et1.count() << std::endl;
}
void test_zarr_pyramid_gen(){
std::string input_zarr_dir = "/home/samee/axle/data/test_assembly";
std::string output_root_dir = "/home/samee/axle/data/test_assembly_out";
auto t1 = std::chrono::high_resolution_clock::now();
auto zarr_pyr_gen = ChunkedBaseToPyramid();
BS::thread_pool<BS::tp::none> th_pool;
auto channel_ds_config = std::unordered_map<std::int64_t, DSType>();
zarr_pyr_gen.CreatePyramidImages(input_zarr_dir, output_root_dir, 17, 1024, VisType::Viv, channel_ds_config, th_pool);
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> et1 = t2-t1;
std::cout << "time for base image: "<< et1.count() << std::endl;
}
void test_ome_tiff_to_zarr_pyramid_gen(){
std::string input_tiff_file = "/home/samee/Downloads/WT_Uninfected_top_right.tif";
//input_tiff_file = "/home/samee/axle/data/test_image.ome.tif";
std::string output_dir = "/mnt/hdd8/axle/data/test_assembly_out";
auto t1 = std::chrono::high_resolution_clock::now();
auto zarr_pyr_gen = OmeTiffToChunkedPyramid();
auto channel_ds_config = std::unordered_map<std::int64_t, DSType>();
zarr_pyr_gen.GenerateFromSingleFile(input_tiff_file, output_dir, 256, VisType::Viv, channel_ds_config);
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> et1 = t2-t1;
std::cout << "time for base image: "<< et1.count() << std::endl;
}
void test_ome_tiff_coll_to_zarr_pyramid_gen(){
std::string input_dir = "/home/samee/axle/data/images";
std::string stitch_vector = "x{x:d+}_y{y:d+}_c{c:d}.ome.tiff";
std::string image_name = "test_image";
std::string output_dir = "/home/samee/axle/data";
auto t1 = std::chrono::high_resolution_clock::now();
auto zarr_pyr_gen = OmeTiffToChunkedPyramid();
auto channel_ds_config = std::unordered_map<std::int64_t, DSType>();
channel_ds_config[1] = DSType::Mean;
channel_ds_config[0] = DSType::Mode_Max;
zarr_pyr_gen.GenerateFromCollection(input_dir, stitch_vector, image_name, output_dir, 1024, VisType::Viv, channel_ds_config);
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> et1 = t2-t1;
std::cout << "time for base image: "<< et1.count() << std::endl;
}
void test_ome_tiff_coll_to_zarr_pyramid_gen_xml(){
std::string input_dir = "/home/samee/axle/data/intensity1";
std::string output_file = "/home/samee/axle/data/test_assembly/test.xml";
std::string stitch_vector = "/home/samee/axle/data/tmp_dir/img-global-positions-1.txt";
std::string image_name = "test_image";
auto zpw = OmeTiffCollToChunked();
auto t1 = std::chrono::high_resolution_clock::now();
BS::thread_pool<BS::tp::none> th_pool;
//zpw.Assemble(input_dir, stitch_vector,output_file, VisType::Viv, th_pool);
ImageInfo a;
zpw.GenerateOmeXML(image_name, output_file, a);
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> et1 = t2-t1;
std::cout << "time for base image: "<< et1.count() << std::endl;
}
void test_npc_write(){
// TENSORSTORE_CHECK_OK_AND_ASSIGN(auto store, tensorstore::Open(
// {{"driver", "neuroglancer_precomputed"},
// {"kvstore", {
// {"driver", "file"},
// {"path", "/home/samee/axle/data/test_ngs"}
// }},
// {"multiscale_metadata", {
// {"data_type", "uint16"},
// {"num_channels", 1},
// {"type", "image"},
// }},
// {"scale_metadata", {
// {"encoding", "raw"},
// {"key", "1"},
// {"size", {16,16,1}},
// {"chunk_size", {4,4,1}},
// }}},
// tensorstore::OpenMode::create |
// tensorstore::OpenMode::delete_existing,
// tensorstore::ReadWriteMode::write).result());
// std::vector<uint16_t> test_input(6);
// for(int i=0; i<test_input.size(); i++){
// test_input[i] = i+1;
// }
// std::cout<<"printing input\n";
// for(auto& x: test_input){
// std::cout<<x<<" ";
// }
// std::cout<<std::endl;
// auto array = tensorstore::Array(test_input.data(), {3, 2}, tensorstore::c_order);
// //auto array = tensorstore::MakeArray<std::uint16_t>({{1, 2, 3}, {4, 5, 6}});
// tensorstore::Write(tensorstore::UnownedToShared(array), store |tensorstore::Dims(2, 3).IndexSlice({0, 0})|
// tensorstore::Dims(0).ClosedInterval(0,2) |
// tensorstore::Dims(1).ClosedInterval(0,1)).value();
TENSORSTORE_CHECK_OK_AND_ASSIGN(auto outstore, tensorstore::Open(
{{"driver", "neuroglancer_precomputed"},
{"kvstore", {
{"driver", "file"},
{"path", "/home/samee/axle/data/test_ngs"}
}}},
tensorstore::OpenMode::open,
tensorstore::ReadWriteMode::read).result());
std::vector<uint16_t> test_output(6);
auto array2 = tensorstore::Array(test_output.data(), {3, 2}, tensorstore::fortran_order);
tensorstore::Read(outstore |tensorstore::Dims(2, 3).IndexSlice({0, 0})|
tensorstore::Dims(0).ClosedInterval(0,2) |
tensorstore::Dims(1).ClosedInterval(0,1), tensorstore::UnownedToShared(array2)).value();
std::cout<<"printing output\n";
for(auto& x: test_output){
std::cout<<x<<" ";
}
std::cout<<std::endl;
// tensorstore::Write(array, store |
// tensorstore::Dims(0).ClosedInterval(0,1) |
// tensorstore::Dims(1).ClosedInterval(0,1) |
// tensorstore::Dims(2).ClosedInterval(0,0) |
// tensorstore::Dims(3).ClosedInterval(0,0)).value();
}
void test_zarr_write(){
TENSORSTORE_CHECK_OK_AND_ASSIGN(auto store, tensorstore::Open(
{{"driver", "zarr"},
{"kvstore", {
{"driver", "file"},
{"path", "/home/samee/axle/data/test_zarr"}
}},
{"metadata", {
{"zarr_format", 2},
{"shape", {1,1,16,16}},
{"chunks", {1,1,4,4}},
{"dtype", "<u2"},
},
}},
tensorstore::OpenMode::create |
tensorstore::OpenMode::delete_existing,
tensorstore::ReadWriteMode::write).result());
auto array = tensorstore::MakeArray<std::uint16_t>({{1, 2}, {4, 5}});
// tensorstore::Write(array, store |tensorstore::Dims(2, 3).IndexSlice({0, 0})|
// tensorstore::Dims(0).ClosedInterval(0,1) |
// tensorstore::Dims(1).ClosedInterval(0,1)).value();
tensorstore::Write(array, store |
tensorstore::Dims(2).ClosedInterval(0,1) |
tensorstore::Dims(3).ClosedInterval(0,1) |
tensorstore::Dims(0).ClosedInterval(0,0) |
tensorstore::Dims(1).ClosedInterval(0,0)).value();
}
*/
void test_pyramid_view(){
std::string base_zarr_path{"/home/samee/axle_data/test_pyramid_view/test1"};
std::string pyramid_zarr_path{"/home/samee/axle_data/test_pyramid_view/test2"};
std::string image_coll_path{"/home/samee/axle_data/aaron_test_data"};
image_map test_data_map{
{"x0_y0_c0.ome.tiff", {0,0,0}},
{"x0_y1_c0.ome.tiff", {0,1,0}},
{"x0_y2_c0.ome.tiff", {0,2,0}},
{"x1_y0_c0.ome.tiff", {1,0,0}},
{"x1_y1_c0.ome.tiff", {1,1,0}},
{"x1_y2_c0.ome.tiff", {1,2,0}},
{"x0_y0_c1.ome.tiff", {0,0,1}},
{"x0_y1_c1.ome.tiff", {0,1,1}},
{"x0_y2_c1.ome.tiff", {0,2,1}},
{"x1_y0_c1.ome.tiff", {1,0,1}},
{"x1_y1_c1.ome.tiff", {1,1,1}},
{"x1_y2_c1.ome.tiff", {1,2,1}}
};
auto tmp = PyramidView(image_coll_path, base_zarr_path, pyramid_zarr_path, "test_image", test_data_map);
std::unordered_map<std::int64_t, DSType> channel_ds_config {{0,DSType::Mean},{1,DSType::Mean}};
tmp.AssembleBaseLevel(VisType::Viv);
tmp.GeneratePyramid(std::nullopt,VisType::Viv,256,channel_ds_config);
// image_map test_data_map_2{
// {"x0_y0_c0.ome.tiff", {0,0,1}},
// {"x0_y1_c0.ome.tiff", {0,1,1}},
// {"x0_y2_c0.ome.tiff", {0,2,1}},
// {"x1_y0_c0.ome.tiff", {1,0,1}},
// {"x1_y1_c0.ome.tiff", {1,1,1}},
// {"x1_y2_c0.ome.tiff", {1,2,1}},
// {"x0_y0_c1.ome.tiff", {0,0,0}},
// {"x0_y1_c1.ome.tiff", {0,1,0}},
// {"x0_y2_c1.ome.tiff", {0,2,0}},
// {"x1_y0_c1.ome.tiff", {1,0,0}},
// {"x1_y1_c1.ome.tiff", {1,1,0}},
// {"x1_y2_c1.ome.tiff", {1,2,0}}
// };
// tmp.GeneratePyramid(test_data_map_2,VisType::Viv,256,channel_ds_config);
// tmp.AssembleBaseLevel(VisType::Viv,test_data_map_2);
}
int main(){
std::cout<<"hello"<<std::endl;
//test_zarr_pyramid_writer();
//test_zarr_pyramid_assembler();
//test_zarr_pyramid_gen();
//test_ome_tiff_to_zarr_pyramid_gen();
//test_ome_tiff_coll_to_zarr_pyramid_gen();
//test_ome_tiff_coll_to_zarr_pyramid_gen_xml();
//test_npc_write();
//test_zarr_write();
test_pyramid_view();
}