Skip to content

Commit 26da565

Browse files
authored
Make image reader stateless to fix cubing (#460)
* test cubing with start_z and padding * make image_reader stateless to fix cubing * fix lint * update changelog * make methods static * unify the static method calls
1 parent 993c6e3 commit 26da565

File tree

6 files changed

+220
-209
lines changed

6 files changed

+220
-209
lines changed

wkcuber/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ For upgrade instructions, please check the respective *Breaking Changes* section
1313
### Added
1414
### Changed
1515
### Fixed
16+
- Fixed two bugs in `cubing` (regarding `start_z` and `pad`). As a result, the ImageConverters do no longer cache metadata. [#460](https://github.com/scalableminds/webknossos-libs/pull/460)
1617

1718
## [v0.8.18](https://github.com/scalableminds/webknossos-cuber/releases/tag/v0.8.18) - 2021-10-18
1819
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v0.8.16...v0.8.18)
7.14 MB
Binary file not shown.
7.14 MB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set -xe
2+
mkdir -p testoutput/tiff_pad
3+
python -m wkcuber.cubing \
4+
--jobs 2 \
5+
--batch_size 8 \
6+
--layer_name color \
7+
--scale 1,1,1 \
8+
--start_z 4 \
9+
--pad \
10+
testdata/tiff_with_different_dimensions testoutput/tiff_pad
11+
[ -d testoutput/tiff_pad/color ]
12+
[ -d testoutput/tiff_pad/color/1 ]
13+
[ -e testoutput/tiff_pad/datasource-properties.json ]

wkcuber/wkcuber/cubing.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
setup_logging,
2929
add_scale_flag,
3030
)
31-
from .image_readers import image_reader, refresh_global_image_reader
31+
from .image_readers import image_reader
3232

3333
BLOCK_LEN = 32
3434

@@ -181,7 +181,6 @@ def cubing_job(
181181
InterpolationModes,
182182
List[str],
183183
int,
184-
Tuple[int, int],
185184
bool,
186185
Optional[int],
187186
Optional[int],
@@ -193,7 +192,6 @@ def cubing_job(
193192
interpolation_mode,
194193
source_file_batches,
195194
batch_size,
196-
image_size,
197195
pad,
198196
channel_index,
199197
sample_index,
@@ -229,15 +227,15 @@ def cubing_job(
229227

230228
if not pad:
231229
assert (
232-
image.shape[0:2] == image_size
230+
image.shape[0:2] == target_view.size[0:2]
233231
), "Section z={} has the wrong dimensions: {} (expected {}). Consider using --pad.".format(
234-
z, image.shape, image_size
232+
z, image.shape, target_view.size[0:2]
235233
)
236234
slices.append(image)
237235

238236
if pad:
239-
x_max = max(_slice.shape[0] for _slice in slices)
240-
y_max = max(_slice.shape[1] for _slice in slices)
237+
x_max = target_view.size[0]
238+
y_max = target_view.size[1]
241239

242240
slices = [
243241
np.pad(
@@ -313,11 +311,16 @@ def cubing(
313311
executor_args: Namespace,
314312
) -> Layer:
315313
source_files = find_source_filenames(source_path)
316-
# we need to refresh the image readers because they are no longer stateless for performance reasons
317-
refresh_global_image_reader()
318314

319-
# All images are assumed to have equal dimensions
320-
num_x, num_y = image_reader.read_dimensions(source_files[0])
315+
all_num_x, all_num_y = zip(
316+
*[
317+
image_reader.read_dimensions(source_files[i])
318+
for i in range(len(source_files))
319+
]
320+
)
321+
num_x = max(all_num_x)
322+
num_y = max(all_num_y)
323+
# All images are assumed to have equal channels and samples
321324
num_channels = image_reader.read_channel_count(source_files[0])
322325
num_samples = image_reader.read_sample_count(source_files[0])
323326
num_output_channels = num_channels * num_samples
@@ -415,13 +418,12 @@ def cubing(
415418
(
416419
target_mag_view.get_view(
417420
(0, 0, z + start_z),
418-
(num_x, num_y, start_z + max_z - z),
421+
(num_x, num_y, max_z - z),
419422
),
420423
target_mag,
421424
interpolation_mode,
422425
source_files_array,
423426
batch_size,
424-
(num_x, num_y),
425427
pad,
426428
channel_index,
427429
sample_index,

0 commit comments

Comments
 (0)