Skip to content

Commit

Permalink
Fix indexing for non-zero starting value
Browse files Browse the repository at this point in the history
  • Loading branch information
sameeul committed Oct 31, 2024
1 parent d633840 commit d1ba3c7
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/cpp/core/chunked_pyramid_assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <thread>
#include <cstdlib>
#include <optional>
#include <climits>

#include "tensorstore/tensorstore.h"
#include "tensorstore/context.h"
Expand Down Expand Up @@ -55,8 +56,6 @@ std::optional<std::int64_t> retrieve_val(const std::string& var, const Map& m){
return {};
}
}


ImageInfo OmeTiffCollToChunked::Assemble(const std::string& input_dir,
const std::string& pattern ,
const std::string& output_file,
Expand All @@ -65,6 +64,7 @@ ImageInfo OmeTiffCollToChunked::Assemble(const std::string& input_dir,
BS::thread_pool& th_pool)
{
int grid_x_max = 0, grid_y_max = 0, grid_c_max = 0;
int grid_x_min = INT_MAX, grid_y_min = INT_MAX, grid_c_min = INT_MAX;
std::vector<ImageSegment> image_vec;
ImageInfo whole_image;

Expand All @@ -81,6 +81,10 @@ ImageInfo OmeTiffCollToChunked::Assemble(const std::string& input_dir,
gc.value() > grid_c_max ? grid_c_max = gc.value() : grid_c_max = grid_c_max;
gx.value() > grid_x_max ? grid_x_max = gx.value() : grid_x_max = grid_x_max;
gy.value() > grid_y_max ? grid_y_max = gy.value() : grid_y_max = grid_y_max;

gc.value() < grid_c_min ? grid_c_min = gc.value() : grid_c_min = grid_c_min;
gx.value() < grid_x_min ? grid_x_min = gx.value() : grid_x_min = grid_x_min;
gy.value() < grid_y_min ? grid_y_min = gy.value() : grid_y_min = grid_y_min;
image_vec.emplace_back(fname, gx.value(), gy.value(), gc.value());
}
}
Expand All @@ -99,9 +103,9 @@ ImageInfo OmeTiffCollToChunked::Assemble(const std::string& input_dir,
auto test_image_shape = test_source.domain().shape();
whole_image._chunk_size_x = test_image_shape[4];
whole_image._chunk_size_y = test_image_shape[3];
whole_image._full_image_width = (grid_x_max+1)*whole_image._chunk_size_x;
whole_image._full_image_height = (grid_y_max+1)*whole_image._chunk_size_y;
whole_image._num_channels = grid_c_max+1;
whole_image._full_image_width = (grid_x_max-grid_x_min+1)*whole_image._chunk_size_x;
whole_image._full_image_height = (grid_y_max-grid_y_min+1)*whole_image._chunk_size_y;
whole_image._num_channels = grid_c_max-grid_c_min+1;

std::vector<std::int64_t> new_image_shape(num_dims,1);
std::vector<std::int64_t> chunk_shape(num_dims,1);
Expand Down Expand Up @@ -131,7 +135,7 @@ ImageInfo OmeTiffCollToChunked::Assemble(const std::string& input_dir,

auto t4 = std::chrono::high_resolution_clock::now();
for(const auto& i: image_vec){
th_pool.push_task([&dest, i, x_dim=x_dim, y_dim=y_dim, c_dim=c_dim, v, &whole_image](){
th_pool.push_task([&dest, i, x_dim=x_dim, y_dim=y_dim, c_dim=c_dim, v, &whole_image, grid_c_min, grid_x_min, grid_y_min]() {


TENSORSTORE_CHECK_OK_AND_ASSIGN(auto source, tensorstore::Open(
Expand All @@ -153,19 +157,19 @@ ImageInfo OmeTiffCollToChunked::Assemble(const std::string& input_dir,

tensorstore::IndexTransform<> transform = tensorstore::IdentityTransform(dest.domain());
if(v == VisType::PCNG){
transform = (std::move(transform) | tensorstore::Dims("z", "channel").IndexSlice({0, i._c_grid})
| tensorstore::Dims(y_dim).SizedInterval(i._y_grid*whole_image._chunk_size_y, image_height)
| tensorstore::Dims(x_dim).SizedInterval(i._x_grid*whole_image._chunk_size_x, image_width)
transform = (std::move(transform) | tensorstore::Dims("z", "channel").IndexSlice({0, i._c_grid-grid_c_min})
| tensorstore::Dims(y_dim).SizedInterval((i._y_grid-grid_y_min)*whole_image._chunk_size_y, image_height)
| tensorstore::Dims(x_dim).SizedInterval((i._x_grid-grid_x_min)*whole_image._chunk_size_x, image_width)
| tensorstore::Dims(x_dim, y_dim).Transpose({y_dim, x_dim})).value();

} else if (v == VisType::NG_Zarr){
transform = (std::move(transform) | tensorstore::Dims(c_dim).SizedInterval(i._c_grid, 1)
| tensorstore::Dims(y_dim).SizedInterval(i._y_grid*whole_image._chunk_size_y, image_height)
| tensorstore::Dims(x_dim).SizedInterval(i._x_grid*whole_image._chunk_size_x, image_width)).value();
transform = (std::move(transform) | tensorstore::Dims(c_dim).SizedInterval(i._c_grid-grid_c_min, 1)
| tensorstore::Dims(y_dim).SizedInterval((i._y_grid-grid_y_min)*whole_image._chunk_size_y, image_height)
| tensorstore::Dims(x_dim).SizedInterval((i._x_grid-grid_x_min)*whole_image._chunk_size_x, image_width)).value();
} else if (v == VisType::Viv){
transform = (std::move(transform) | tensorstore::Dims(c_dim).SizedInterval(i._c_grid, 1)
| tensorstore::Dims(y_dim).SizedInterval(i._y_grid*whole_image._chunk_size_y, image_height)
| tensorstore::Dims(x_dim).SizedInterval(i._x_grid*whole_image._chunk_size_x, image_width)).value();
transform = (std::move(transform) | tensorstore::Dims(c_dim).SizedInterval(i._c_grid-grid_c_min, 1)
| tensorstore::Dims(y_dim).SizedInterval((i._y_grid-grid_y_min)*whole_image._chunk_size_y, image_height)
| tensorstore::Dims(x_dim).SizedInterval((i._x_grid-grid_x_min)*whole_image._chunk_size_x, image_width)).value();
}
tensorstore::Write(array, dest | transform).value();
});
Expand Down

0 comments on commit d1ba3c7

Please sign in to comment.