Skip to content

Commit 3a5aa89

Browse files
fm3jstriebel
andauthored
Handle axis offsets in czi files (#876)
* Handle axis offsets in czi files * format --------- Co-authored-by: Jonathan Striebel <[email protected]>
1 parent 502a11b commit 3a5aa89

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1919
### Changed
2020

2121
### Fixed
22+
- Fixed reading czi files with non-zero axis offsets. [#876](https://github.com/scalableminds/webknossos-libs/pull/876)
2223

2324

2425
## [0.12.2](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.12.2) - 2023-02-20

webknossos/webknossos/dataset/_utils/pims_czi_reader.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from contextlib import contextmanager
22
from os import PathLike
33
from pathlib import Path
4-
from typing import Iterator, List, Set
4+
from typing import Dict, Iterator, List, Set
55

66
import numpy as np
77

@@ -47,20 +47,23 @@ def class_exts(cls) -> Set[str]:
4747
def __init__(self, path: PathLike, czi_channel: int = 0) -> None:
4848
self.path = Path(path)
4949
self.czi_channel = czi_channel
50+
self.axis_offsets: Dict[str, int] = {}
5051
super().__init__()
5152
with self.czi_file() as czi_file:
5253
for axis, (
5354
start,
54-
length,
55+
end,
5556
) in czi_file.total_bounding_box.items():
5657
axis = axis.lower()
5758
if axis == "c":
5859
continue
59-
assert start == 0
60+
length = end - start
6061
if axis not in "xy" and length == 1:
6162
# not propagating axes of length one
6263
continue
64+
assert length >= 0, f"axis length must be >= 0, got {length}"
6365
self._init_axis(axis, length)
66+
self.axis_offsets[axis] = start
6467
self._czi_pixel_type = czi_file.get_channel_pixel_type(self.czi_channel)
6568
if self._czi_pixel_type.startswith("Bgra"):
6669
self._init_axis("c", 4)
@@ -94,6 +97,9 @@ def pixel_type(self) -> np.dtype:
9497

9598
def get_frame_2D(self, **ind: int) -> np.ndarray:
9699
plane = {k.upper(): v for k, v in ind.items()}
100+
for axis in plane.keys():
101+
if axis in self.axis_offsets:
102+
plane[axis] += self.axis_offsets[axis]
97103

98104
# safe-guard against x/y in ind argument,
99105
# we always read the whole slice here:

0 commit comments

Comments
 (0)