Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indexing for non-zero starting value #21

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading