Skip to content

Commit

Permalink
Fix wrong dimension in metadata (#248)
Browse files Browse the repository at this point in the history
Fix a wrong value assignment for the loaded region image.

Fixes #247

Signed-off-by: Gigon Bae <gbae@nvidia.com>

Authors:
  - Gigon Bae (https://github.com/gigony)

Approvers:
  - https://github.com/jakirkham

URL: #248
  • Loading branch information
gigony authored Mar 31, 2022
1 parent b4084a5 commit 3d78d6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cpp/src/cuimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,16 +848,16 @@ CuImage CuImage::read_region(std::vector<int64_t>&& location,
const uint16_t level_ndim = 2;
std::pmr::vector<int64_t> level_dimensions(&resource);
level_dimensions.reserve(level_ndim * 1); // it has only one size
level_dimensions.insert(level_dimensions.end(), request.location, &request.location[request.location_len]);
level_dimensions.insert(level_dimensions.end(), request.size, &request.size[request.size_ndim]);

std::pmr::vector<float> level_downsamples(&resource);
level_downsamples.reserve(1);
level_downsamples.emplace_back(1.0);

std::pmr::vector<uint32_t> level_tile_sizes(&resource);
level_tile_sizes.reserve(level_ndim * 1); // it has only one size
level_tile_sizes.insert(
level_tile_sizes.end(), request.location, &request.location[request.location_len]); // same with level_dimension
level_tile_sizes.insert(level_tile_sizes.end(), request.size, &request.size[request.size_ndim]); // same with
// level_dimension

// Empty associated images
const size_t associated_image_count = 0;
Expand Down
17 changes: 16 additions & 1 deletion python/cucim/tests/unit/clara/test_tiff_read_region.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021, NVIDIA CORPORATION.
# Copyright (c) 2021-2022, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -113,6 +113,21 @@ def test_tiff_stripe_multiresolution(testimg_tiff_stripe_4096x4096_256):
min(img_size[1], 256))


def test_region_image_level_data(testimg_tiff_stripe_4096x4096_256):
cucim_img = open_image_cucim(testimg_tiff_stripe_4096x4096_256)

level_count = cucim_img.resolutions['level_count']

start_pos, size = ((-10, -20), (300, 400))
for level in range(level_count):
region_img = cucim_img.read_region(start_pos, size, level)
resolutions = region_img.resolutions
assert resolutions["level_count"] == 1
assert resolutions["level_dimensions"][0] == (300, 400)
assert resolutions["level_downsamples"] == (1.0,)
assert resolutions["level_tile_sizes"][0] == (300, 400)


def test_array_interface_support(testimg_tiff_stripe_32x24_16_jpeg):
img = open_image_cucim(testimg_tiff_stripe_32x24_16_jpeg)
whole_img = img.read_region()
Expand Down

0 comments on commit 3d78d6f

Please sign in to comment.