micro-reader 0.4.0__tar.gz → 0.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {micro_reader-0.4.0 → micro_reader-0.4.2}/PKG-INFO +7 -7
- {micro_reader-0.4.0 → micro_reader-0.4.2}/README.md +5 -5
- {micro_reader-0.4.0 → micro_reader-0.4.2}/pyproject.toml +2 -2
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_codecs.py +33 -13
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_mosaic.py +2 -2
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_version.py +1 -1
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_czi_metadata.py +1 -1
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/bdv.py +110 -5
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/czi.py +24 -10
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/oir.py +15 -1
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/tiff.py +12 -2
- {micro_reader-0.4.0 → micro_reader-0.4.2}/.gitignore +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/LICENSE +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/__init__.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_axes.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_base.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_cfb.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_errors.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_eubi_guard.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_fileset.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_groups.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_index.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_io.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_jpeg_restarts.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_lambda.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_memory.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_metadata.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_naming.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_outline.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_parts.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_plate.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_pool.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_registry.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_spatial.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_stack.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/_stream.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/__init__.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_ets.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_hdf5.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_lif_metadata.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_nd2_legacy.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_nd2_metadata.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_nd2_run.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_nd2_structure.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_tiff_metadata.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_tiff_variants.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/_vsi_tree.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/cellomics.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/columbus.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/companion.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/cv7000.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/dv.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/flex.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/harmony.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/hdf5.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/ics.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/ilastik.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/ims.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/incell.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/jdce.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/klb.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/lif.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/luxendo.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/metamorph.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/metaxpress.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/micromanager.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/mrc.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/nd2.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/ndpis.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/oif.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/omp2info.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/raster.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/scanr.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.2}/src/micro_reader/backends/vsi.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: micro-reader
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: Low-level, memory-bounded pixel reading for microscopy formats: read exactly the rectangle you ask for.
|
|
5
5
|
Project-URL: Homepage, https://github.com/bugraoezdemir/micro-reader
|
|
6
6
|
Project-URL: Source, https://github.com/bugraoezdemir/micro-reader
|
|
@@ -18,7 +18,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.14
|
|
19
19
|
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
20
20
|
Requires-Python: >=3.11
|
|
21
|
-
Requires-Dist: micro-reader-codecs<0.1,>=0.0.
|
|
21
|
+
Requires-Dist: micro-reader-codecs<0.1,>=0.0.3
|
|
22
22
|
Requires-Dist: numpy>=1.24
|
|
23
23
|
Requires-Dist: tifffile>=2025.5.21
|
|
24
24
|
Provides-Extra: all
|
|
@@ -73,8 +73,8 @@ pip install micro-reader
|
|
|
73
73
|
Optional support:
|
|
74
74
|
|
|
75
75
|
```bash
|
|
76
|
-
pip install "micro-reader[
|
|
77
|
-
pip install "micro-reader[codecs]" #
|
|
76
|
+
pip install "micro-reader[hdf5]" # Imaris (.ims), ilastik, BigDataViewer, Luxendo, Fiji HDF5
|
|
77
|
+
pip install "micro-reader[codecs]" # LERC, CCITT fax and other rare TIFF codecs
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
## Quick start
|
|
@@ -657,7 +657,7 @@ Supported codecs include:
|
|
|
657
657
|
* PNG
|
|
658
658
|
* EER
|
|
659
659
|
|
|
660
|
-
|
|
660
|
+
JPEG (NDPI's included) and JPEG XR decode with libjpeg-turbo and jxrlib, built into micro-reader-codecs: the decoders imagecodecs uses, with its pixels and speed. LERC, CCITT fax, float24 and a few rarer codecs need imagecodecs:
|
|
661
661
|
|
|
662
662
|
```bash
|
|
663
663
|
pip install "micro-reader[codecs]"
|
|
@@ -704,7 +704,7 @@ CZI files support:
|
|
|
704
704
|
CZI-specific operations include:
|
|
705
705
|
|
|
706
706
|
```python
|
|
707
|
-
image.read_region(x,
|
|
707
|
+
image.read_region(y=y, x=x, height=h, width=w)
|
|
708
708
|
```
|
|
709
709
|
|
|
710
710
|
and:
|
|
@@ -713,7 +713,7 @@ and:
|
|
|
713
713
|
f.canvas()
|
|
714
714
|
```
|
|
715
715
|
|
|
716
|
-
`image.origin` gives the image corner in the file's pixel coordinates.
|
|
716
|
+
`image.origin` gives the image corner `(y, x)` in the file's pixel coordinates.
|
|
717
717
|
|
|
718
718
|
Damaged subblock directories can be recovered with a `DamagedFileWarning`. Details are available through:
|
|
719
719
|
|
|
@@ -19,8 +19,8 @@ pip install micro-reader
|
|
|
19
19
|
Optional support:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
pip install "micro-reader[
|
|
23
|
-
pip install "micro-reader[codecs]" #
|
|
22
|
+
pip install "micro-reader[hdf5]" # Imaris (.ims), ilastik, BigDataViewer, Luxendo, Fiji HDF5
|
|
23
|
+
pip install "micro-reader[codecs]" # LERC, CCITT fax and other rare TIFF codecs
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
## Quick start
|
|
@@ -603,7 +603,7 @@ Supported codecs include:
|
|
|
603
603
|
* PNG
|
|
604
604
|
* EER
|
|
605
605
|
|
|
606
|
-
|
|
606
|
+
JPEG (NDPI's included) and JPEG XR decode with libjpeg-turbo and jxrlib, built into micro-reader-codecs: the decoders imagecodecs uses, with its pixels and speed. LERC, CCITT fax, float24 and a few rarer codecs need imagecodecs:
|
|
607
607
|
|
|
608
608
|
```bash
|
|
609
609
|
pip install "micro-reader[codecs]"
|
|
@@ -650,7 +650,7 @@ CZI files support:
|
|
|
650
650
|
CZI-specific operations include:
|
|
651
651
|
|
|
652
652
|
```python
|
|
653
|
-
image.read_region(x,
|
|
653
|
+
image.read_region(y=y, x=x, height=h, width=w)
|
|
654
654
|
```
|
|
655
655
|
|
|
656
656
|
and:
|
|
@@ -659,7 +659,7 @@ and:
|
|
|
659
659
|
f.canvas()
|
|
660
660
|
```
|
|
661
661
|
|
|
662
|
-
`image.origin` gives the image corner in the file's pixel coordinates.
|
|
662
|
+
`image.origin` gives the image corner `(y, x)` in the file's pixel coordinates.
|
|
663
663
|
|
|
664
664
|
Damaged subblock directories can be recovered with a `DamagedFileWarning`. Details are available through:
|
|
665
665
|
|
|
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "micro-reader"
|
|
9
|
-
version = "0.4.
|
|
9
|
+
version = "0.4.2"
|
|
10
10
|
description = "Low-level, memory-bounded pixel reading for microscopy formats: read exactly the rectangle you ask for."
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
requires-python = ">=3.11"
|
|
@@ -29,7 +29,7 @@ classifiers = [
|
|
|
29
29
|
# TIFF covers most microscopy images, so it is not an extra (Bugra,
|
|
30
30
|
# 2026-10-01) until micro-reader parses TIFF itself (post-0.0.1). The floor
|
|
31
31
|
# matches eubi-bridge's (tifffile>=2025.5.21), so both install together.
|
|
32
|
-
dependencies = ["numpy>=1.24", "micro-reader-codecs>=0.0.
|
|
32
|
+
dependencies = ["numpy>=1.24", "micro-reader-codecs>=0.0.3,<0.1", "tifffile>=2025.5.21"]
|
|
33
33
|
|
|
34
34
|
[project.urls]
|
|
35
35
|
Homepage = "https://github.com/bugraoezdemir/micro-reader"
|
|
@@ -76,16 +76,26 @@ def zstd_decompress_into(data, out: np.ndarray, *, native: bool | None = None) -
|
|
|
76
76
|
raise CorruptFileError(f"zstd data decodes to {written} bytes, expected {len(view)}")
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
def _imagecodecs(what: str):
|
|
79
|
+
def _imagecodecs(what: str, native_from: str | None = None):
|
|
80
|
+
"""imagecodecs, or an error naming the way out: *native_from*, the
|
|
81
|
+
micro-reader-codecs release whose native decoder reads it, when there is one."""
|
|
80
82
|
try:
|
|
81
83
|
import imagecodecs
|
|
82
84
|
except ImportError as exc:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
fix = 'pip install "micro-reader[codecs]"'
|
|
86
|
+
if native_from:
|
|
87
|
+
fix = (f'pip install -U "micro-reader-codecs>={native_from}" (its own decoder), '
|
|
88
|
+
f"or {fix}")
|
|
89
|
+
raise MicroReaderError(f"{what} needs a decoder that is not installed: {fix}") from exc
|
|
86
90
|
return imagecodecs
|
|
87
91
|
|
|
88
92
|
|
|
93
|
+
def has_libjpeg_turbo() -> bool:
|
|
94
|
+
"""micro-reader-codecs links libjpeg-turbo (0.0.3 on): every JPEG micro-reader
|
|
95
|
+
decodes, NDPI's and 12-bit ones included, at its speed and with its pixels."""
|
|
96
|
+
return bool(getattr(_native, "HAS_LIBJPEG_TURBO", False))
|
|
97
|
+
|
|
98
|
+
|
|
89
99
|
def _use_native(native, name: str) -> bool:
|
|
90
100
|
if native is None:
|
|
91
101
|
return _native is not None and hasattr(_native, name)
|
|
@@ -360,11 +370,14 @@ def jpeg_decode_into(data, out: np.ndarray, *, colour: str = "auto",
|
|
|
360
370
|
samples]) little-endian, colour in R, G, B order. Returns (width,
|
|
361
371
|
height, samples, bits). *colour*: "auto" (the JPEG's own markers),
|
|
362
372
|
"ycbcr", or "rgb" (stored without a colour transform: TIFF Photometric
|
|
363
|
-
RGB).
|
|
364
|
-
(imagecodecs, tifffile
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
373
|
+
RGB). With micro-reader-codecs 0.0.3 on, libjpeg-turbo itself decodes
|
|
374
|
+
(the decoder of imagecodecs, tifffile and Pillow): its pixels and speed,
|
|
375
|
+
for 8-bit, 12-bit and lossless JPEG. Before, baseline and extended 8-bit
|
|
376
|
+
JPEG decoded to libjpeg-turbo's pixels, bit for bit, progressive JPEG
|
|
377
|
+
could differ by a few grey levels, and 12-bit lossy JPEG went to
|
|
378
|
+
imagecodecs."""
|
|
379
|
+
if _use_native(native, "jpeg_decode_into") and (
|
|
380
|
+
has_libjpeg_turbo() or not _is_12bit_lossy_jpeg(data)):
|
|
368
381
|
try:
|
|
369
382
|
return _native.jpeg_decode_into(data, memoryview(out).cast("B"), colour)
|
|
370
383
|
except ValueError as exc:
|
|
@@ -402,10 +415,17 @@ def jxl_decode_into(data, out: np.ndarray, *, native: bool | None = None):
|
|
|
402
415
|
image.dtype.itemsize * 8)
|
|
403
416
|
|
|
404
417
|
|
|
405
|
-
def jpegxr_decode_into(data, out: np.ndarray):
|
|
406
|
-
"""A JPEG XR codestream -> *out* (colour R, G, B).
|
|
407
|
-
|
|
408
|
-
|
|
418
|
+
def jpegxr_decode_into(data, out: np.ndarray, *, native: bool | None = None):
|
|
419
|
+
"""A JPEG XR codestream -> *out* (colour R, G, B; fixed point as float32).
|
|
420
|
+
micro-reader-codecs 0.0.3 on decodes it with jxrlib, as imagecodecs does and
|
|
421
|
+
with the same pixel-format conversions; imagecodecs otherwise."""
|
|
422
|
+
if _use_native(native, "jpegxr_decode_into"):
|
|
423
|
+
try:
|
|
424
|
+
_native.jpegxr_decode_into(data, memoryview(out).cast("B"))
|
|
425
|
+
return
|
|
426
|
+
except ValueError as exc:
|
|
427
|
+
raise CorruptFileError(f"corrupt JPEG XR data: {exc}") from exc
|
|
428
|
+
codecs = _imagecodecs("JPEG XR data", native_from="0.0.3")
|
|
409
429
|
try:
|
|
410
430
|
image = codecs.jpegxr_decode(bytes(data))
|
|
411
431
|
except Exception as exc: # noqa: BLE001
|
|
@@ -19,7 +19,7 @@ class Mosaic(Image):
|
|
|
19
19
|
"""*tiles*: ``[(image, y, x)]`` in drawing order (later on top), with each
|
|
20
20
|
tile's corner in canvas pixels. The tiles share axes, pixel type and
|
|
21
21
|
every size but ``y`` / ``x``. The canvas starts at the smallest corner
|
|
22
|
-
(``origin``: that corner, in the tiles' pixel grid)."""
|
|
22
|
+
(``origin``: that corner as ``(y, x)`` in the tiles' pixel grid)."""
|
|
23
23
|
|
|
24
24
|
def __init__(self, position: int, tiles: list, name: str, index: dict, fill=0):
|
|
25
25
|
first = tiles[0][0]
|
|
@@ -41,7 +41,7 @@ class Mosaic(Image):
|
|
|
41
41
|
super().__init__(position, first.axes, shape, first.dtype, name=name, index=index)
|
|
42
42
|
self._yi, self._xi = yi, xi
|
|
43
43
|
self._tiles = [(t, y - y0, x - x0) for t, y, x in tiles]
|
|
44
|
-
#: the canvas corner in the tiles' pixel grid
|
|
44
|
+
#: the canvas corner in the tiles' pixel grid, (y, x) as on every image
|
|
45
45
|
self.origin = (y0, x0)
|
|
46
46
|
self._fill = fill
|
|
47
47
|
self._closed = False
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""micro-reader's version, in one place (the package, the import guard)."""
|
|
2
|
-
__version__ = "0.4.
|
|
2
|
+
__version__ = "0.4.2"
|
|
@@ -221,7 +221,7 @@ def first_pixel_position(image, centre: dict, s, sizes: dict) -> dict:
|
|
|
221
221
|
the whole file, so the offset between the two frames found at *s* holds
|
|
222
222
|
for the image's corner too."""
|
|
223
223
|
out = {}
|
|
224
|
-
origin = dict(zip("
|
|
224
|
+
origin = dict(zip("yx", image.origin))
|
|
225
225
|
extent = {"x": s.width, "y": s.height}
|
|
226
226
|
start = {"x": s.x, "y": s.y}
|
|
227
227
|
for axis, q in centre.items():
|
|
@@ -21,7 +21,13 @@ HDF5::
|
|
|
21
21
|
|
|
22
22
|
Images: one per tile, angle and illumination (indices ``tile``, ``view``,
|
|
23
23
|
``illumination``, each only when it takes several values), its channels the
|
|
24
|
-
``c`` axis and its time points the ``t`` axis: ``tczyx``.
|
|
24
|
+
``c`` axis and its time points the ``t`` axis: ``tczyx``. With
|
|
25
|
+
``tiles="mosaic"`` the tiles of each angle and illumination are one image
|
|
26
|
+
(``_mosaic.Mosaic``): every level of the tiles placed on one canvas at their
|
|
27
|
+
nominal positions (below), a whole number of pixels from its corner, the later
|
|
28
|
+
tile on top where they overlap; nothing registered or blended. Tiles that
|
|
29
|
+
cannot be placed so (no position, positions apart along z, different pixel
|
|
30
|
+
sizes) are refused: read them with ``tiles="separate"``. Stored levels are
|
|
25
31
|
the image's ``resolutions``. BigDataViewer stores unsigned 16-bit pixels as
|
|
26
32
|
signed 16-bit HDF5 data; they are read as ``uint16``.
|
|
27
33
|
|
|
@@ -64,6 +70,7 @@ import numpy as np
|
|
|
64
70
|
|
|
65
71
|
from .. import _parts
|
|
66
72
|
from .._base import File, Image
|
|
73
|
+
from .._mosaic import Mosaic
|
|
67
74
|
from .._errors import (CompositeWarning, CorruptFileError, MissingImagesWarning,
|
|
68
75
|
UnsupportedFormatError)
|
|
69
76
|
from .._metadata import Channel, Metadata, Quantity, quantity
|
|
@@ -455,6 +462,106 @@ class _BdvImage(Image):
|
|
|
455
462
|
self._closed = True
|
|
456
463
|
|
|
457
464
|
|
|
465
|
+
class _BdvMosaic(Mosaic):
|
|
466
|
+
"""The tiles of one angle / illumination at one level on one canvas
|
|
467
|
+
(``tiles="mosaic"``); its metadata is the first tile's, placed at the canvas
|
|
468
|
+
corner."""
|
|
469
|
+
|
|
470
|
+
def __init__(self, position, tiles, name, index, corner: dict, members: set):
|
|
471
|
+
super().__init__(position, tiles, name, index)
|
|
472
|
+
self._corner = corner # axis -> Quantity of the canvas corner
|
|
473
|
+
self._members = members
|
|
474
|
+
self._own_name = None
|
|
475
|
+
|
|
476
|
+
def _read_metadata(self):
|
|
477
|
+
from dataclasses import replace
|
|
478
|
+
md = self._tiles[0][0].metadata
|
|
479
|
+
return replace(md, position={**md.position, **self._corner})
|
|
480
|
+
|
|
481
|
+
def _member_paths(self) -> set:
|
|
482
|
+
return set(self._members)
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
class _PlacedViews:
|
|
486
|
+
"""The placement of a mosaic: its canvas corner, a position in ``GLOBAL``
|
|
487
|
+
and no edge (the tiles' registrations do not carry over to the canvas)."""
|
|
488
|
+
|
|
489
|
+
def __init__(self, position: dict):
|
|
490
|
+
self._placement = _Placement(position)
|
|
491
|
+
|
|
492
|
+
def placement(self) -> "_Placement":
|
|
493
|
+
return self._placement
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def _mosaics(pyramids: list, where: str) -> list:
|
|
497
|
+
"""Each angle / illumination's tile pyramids as one pyramid of mosaics: every
|
|
498
|
+
level's tiles at their nominal positions (``_place``), in pixels of that level
|
|
499
|
+
from the canvas corner, rounded to whole pixels (as LIF tile scans are); drawn in
|
|
500
|
+
tile order, the later on top. Refused (UnsupportedFormatError, naming why) when a
|
|
501
|
+
tile has no position along y and x, the tiles lie apart along another axis (the
|
|
502
|
+
canvas is a y / x plane), or their pixel sizes or numbers of levels differ."""
|
|
503
|
+
groups: dict = {}
|
|
504
|
+
for pyramid in pyramids:
|
|
505
|
+
key = tuple((k, v) for k, v in pyramid[0].index.items() if k != "tile")
|
|
506
|
+
groups.setdefault(key, []).append(pyramid)
|
|
507
|
+
out = []
|
|
508
|
+
for key, members in groups.items():
|
|
509
|
+
members.sort(key=lambda pyramid: pyramid[0].index["tile"])
|
|
510
|
+
label = " ".join(f"{k} {v}" for k, v in key if k != "series")
|
|
511
|
+
what = f"{where}: tiles='mosaic'{f' ({label})' if label else ''}"
|
|
512
|
+
placed = [pyramid[0]._views.placement().position for pyramid in members]
|
|
513
|
+
if any(not {"x", "y"} <= set(position) for position in placed):
|
|
514
|
+
raise UnsupportedFormatError(
|
|
515
|
+
f"{what}: a tile has no position on the acquisition grid (its views turn, "
|
|
516
|
+
f"shear or mirror, or disagree): read the tiles with tiles='separate'")
|
|
517
|
+
for axis in sorted(set().union(*placed) - {"x", "y"}):
|
|
518
|
+
values = {round(position[axis].to(placed[0][axis].unit).value, 9)
|
|
519
|
+
for position in placed if axis in position}
|
|
520
|
+
if len(values) > 1 or any(axis not in position for position in placed):
|
|
521
|
+
raise UnsupportedFormatError(
|
|
522
|
+
f"{what}: the tiles lie apart along {axis} ({sorted(values)}); a mosaic "
|
|
523
|
+
f"places tiles in y and x only: read them with tiles='separate'")
|
|
524
|
+
sizes = [pyramid[0].metadata.pixel_sizes for pyramid in members]
|
|
525
|
+
unit = placed[0]["x"].unit
|
|
526
|
+
steps = []
|
|
527
|
+
for axis in "yx":
|
|
528
|
+
if any(axis not in size for size in sizes):
|
|
529
|
+
raise UnsupportedFormatError(f"{what}: a tile has no pixel size along {axis}")
|
|
530
|
+
values = {round(size[axis].to(unit).value, 12) for size in sizes}
|
|
531
|
+
if len(values) != 1:
|
|
532
|
+
raise UnsupportedFormatError(f"{what}: the tiles' pixel sizes along {axis} "
|
|
533
|
+
f"differ ({sorted(values)})")
|
|
534
|
+
steps.append(values.pop())
|
|
535
|
+
if len({len(pyramid) for pyramid in members}) != 1:
|
|
536
|
+
raise UnsupportedFormatError(f"{what}: the tiles store different numbers of "
|
|
537
|
+
f"levels {sorted({len(p) for p in members})}")
|
|
538
|
+
y0 = min(position["y"].to(unit).value for position in placed)
|
|
539
|
+
x0 = min(position["x"].to(unit).value for position in placed)
|
|
540
|
+
offsets = [((position["y"].to(unit).value - y0) / steps[0],
|
|
541
|
+
(position["x"].to(unit).value - x0) / steps[1]) for position in placed]
|
|
542
|
+
corner = {"y": Quantity(y0, unit), "x": Quantity(x0, unit)}
|
|
543
|
+
views = _PlacedViews({**placed[0], **corner})
|
|
544
|
+
files = set().union(*(pyramid[0]._member_paths() for pyramid in members))
|
|
545
|
+
mosaic_pyramid = []
|
|
546
|
+
for level in range(len(members[0])):
|
|
547
|
+
canvas = []
|
|
548
|
+
for pyramid, (dy, dx) in zip(members, offsets):
|
|
549
|
+
base, image = pyramid[0], pyramid[level]
|
|
550
|
+
fy = base.shape[-2] / image.shape[-2] # this level's downsampling
|
|
551
|
+
fx = base.shape[-1] / image.shape[-1]
|
|
552
|
+
canvas.append((image, round(dy / fy), round(dx / fx)))
|
|
553
|
+
first = members[0][level]
|
|
554
|
+
index = {k: v for k, v in first.index.items() if k != "tile"}
|
|
555
|
+
name = f"{where} {label}".strip()
|
|
556
|
+
mosaic = _BdvMosaic(0, canvas, name, index, corner, files)
|
|
557
|
+
mosaic._views = views
|
|
558
|
+
mosaic_pyramid.append(mosaic)
|
|
559
|
+
for mosaic in mosaic_pyramid:
|
|
560
|
+
mosaic._resolutions = mosaic_pyramid
|
|
561
|
+
out.append(mosaic_pyramid)
|
|
562
|
+
return out
|
|
563
|
+
|
|
564
|
+
|
|
458
565
|
def _pixel_type(datasets, declared: set, where: str):
|
|
459
566
|
"""(dtype the image has, view to apply to the stored values or None).
|
|
460
567
|
bdv-core (Hdf5ImageLoader): a setup group's ``dataType`` attribute names the
|
|
@@ -558,10 +665,6 @@ def _build(h5, path: str, xml: Optional[_Xml], resolutions: str, tiles: str,
|
|
|
558
665
|
else:
|
|
559
666
|
dims, index_names, ranks = ["sequence"], ["sequence"], {"sequence": [s.id for s in setups]}
|
|
560
667
|
groups = {(s.id,): [s] for s in setups}
|
|
561
|
-
if tiles == "mosaic" and "tile" in index_names:
|
|
562
|
-
raise UnsupportedFormatError(f"{where}: tiles='mosaic': micro-reader does not compose "
|
|
563
|
-
"BigDataViewer tiles (each tile is its own image)")
|
|
564
|
-
|
|
565
668
|
absent = []
|
|
566
669
|
images_by_level = []
|
|
567
670
|
for g, (gkey, group) in enumerate(sorted(groups.items())):
|
|
@@ -622,6 +725,8 @@ def _build(h5, path: str, xml: Optional[_Xml], resolutions: str, tiles: str,
|
|
|
622
725
|
image._resolutions = pyramid
|
|
623
726
|
image._own_name = own
|
|
624
727
|
images_by_level.append(pyramid)
|
|
728
|
+
if tiles == "mosaic" and "tile" in index_names and images_by_level:
|
|
729
|
+
images_by_level = _mosaics(images_by_level, where)
|
|
625
730
|
lost = getattr(xml, "missing_files", [])
|
|
626
731
|
lost_text = (f"; {len(lost)} of the partition files the XML lists are missing (e.g. "
|
|
627
732
|
f"{lost[0]!r})" if lost else "")
|
|
@@ -395,7 +395,7 @@ class _CziImage(Image):
|
|
|
395
395
|
y0 = min(s.y for s in subblocks)
|
|
396
396
|
x1 = max(s.x + s.width for s in subblocks)
|
|
397
397
|
y1 = max(s.y + s.height for s in subblocks)
|
|
398
|
-
self.
|
|
398
|
+
self._xy = (x0, y0) # series box corner, file pixel coordinates (x, y)
|
|
399
399
|
# plane -> subblocks in drawing order: series, mosaic index, directory
|
|
400
400
|
# order (libCZI's order; the series only matters on the whole-file canvas)
|
|
401
401
|
by_plane: dict = {}
|
|
@@ -406,7 +406,7 @@ class _CziImage(Image):
|
|
|
406
406
|
s.plane.get(d, czi._dim_starts.get(d, 0)) - czi._dim_starts.get(d, 0)
|
|
407
407
|
for d in axes)
|
|
408
408
|
by_plane.setdefault(key, []).append(s)
|
|
409
|
-
self._planes = {key: _PlaneTiles(tiles, self.
|
|
409
|
+
self._planes = {key: _PlaneTiles(tiles, self._xy) for key, tiles in by_plane.items()}
|
|
410
410
|
shape = [len(ids) if d == "C" and ids is not None else czi._dim_sizes.get(d, 1)
|
|
411
411
|
for d in axes] + [y1 - y0, x1 - x0]
|
|
412
412
|
letters = "".join(d.lower() for d in axes) + "yx"
|
|
@@ -564,7 +564,7 @@ class _CziImage(Image):
|
|
|
564
564
|
def _draw(self, s: Subblock, piece, band_y0, xs, dst) -> int:
|
|
565
565
|
"""Draw *piece* (y0, y1, x0, x1 in series coordinates, inside subblock
|
|
566
566
|
*s* and inside the band) onto *dst* (the band: rows, cols[, samples])."""
|
|
567
|
-
ox, oy = self.
|
|
567
|
+
ox, oy = self._xy
|
|
568
568
|
sy0, sx0 = s.y - oy, s.x - ox # tile's place in the series
|
|
569
569
|
y0, y1, x0, x1 = piece
|
|
570
570
|
item = self._file_dtype.itemsize * self._samples
|
|
@@ -643,7 +643,7 @@ class _CziImage(Image):
|
|
|
643
643
|
"""*piece* of subblock *s* from its rows alone, decoded as a stream in
|
|
644
644
|
pieces of rows, each held within the memory budget."""
|
|
645
645
|
codec, offset, length = source
|
|
646
|
-
ox, oy = self.
|
|
646
|
+
ox, oy = self._xy
|
|
647
647
|
sy0, sx0 = s.y - oy, s.x - ox
|
|
648
648
|
y0, y1, x0, x1 = piece
|
|
649
649
|
row = s.width * self._samples
|
|
@@ -668,7 +668,7 @@ class _CziImage(Image):
|
|
|
668
668
|
covering it) or of a JPEG subblock with restart markers (cut out of
|
|
669
669
|
it, ``_jpeg_restarts``), in bands of rows within the budget; None
|
|
670
670
|
for a JPEG that cannot be cut."""
|
|
671
|
-
ox, oy = self.
|
|
671
|
+
ox, oy = self._xy
|
|
672
672
|
sy0, sx0 = s.y - oy, s.x - ox
|
|
673
673
|
y0, y1, x0, x1 = piece
|
|
674
674
|
base, size = self._data_offset(s), s.data_size
|
|
@@ -733,7 +733,7 @@ class _CziImage(Image):
|
|
|
733
733
|
def _draw_span(self, s: Subblock, pieces, band_y0, xs, dst) -> int:
|
|
734
734
|
"""Uncompressed *pieces* of subblock *s* from ONE contiguous read: from
|
|
735
735
|
the first piece pixel to the last, the bytes between them included."""
|
|
736
|
-
ox, oy = self.
|
|
736
|
+
ox, oy = self._xy
|
|
737
737
|
sy0, sx0 = s.y - oy, s.x - ox
|
|
738
738
|
by0, by1 = min(p[0] for p in pieces), max(p[1] for p in pieces)
|
|
739
739
|
bx0, bx1 = min(p[2] for p in pieces), max(p[3] for p in pieces)
|
|
@@ -808,14 +808,28 @@ class _CziImage(Image):
|
|
|
808
808
|
out = out[..., ss]
|
|
809
809
|
return out, read
|
|
810
810
|
|
|
811
|
-
|
|
811
|
+
@property
|
|
812
|
+
def origin(self) -> tuple:
|
|
813
|
+
"""``(y, x)`` of the series' corner in the file's own pixel coordinates
|
|
814
|
+
(libCZI's bounding box; libCZI writes it x first)."""
|
|
815
|
+
x, y = self._xy
|
|
816
|
+
return (y, x)
|
|
817
|
+
|
|
818
|
+
def read_region(self, *args, y: int = None, x: int = None, height: int = None,
|
|
819
|
+
width: int = None, **planes) -> np.ndarray:
|
|
812
820
|
"""A rectangle in the file's own pixel coordinates (libCZI's ``roi``,
|
|
813
821
|
e.g. from ``origin`` or the XML metadata), composed from this series'
|
|
814
822
|
tiles; parts outside the series' box are background (0), as libCZI
|
|
815
|
-
returns them. *planes* select the other axes like ``read``.
|
|
823
|
+
returns them. *planes* select the other axes like ``read``. Keywords
|
|
824
|
+
only: before 0.4.2 it took ``(x, y, width, height)`` by position, so a
|
|
825
|
+
positional call is refused rather than read with y and x swapped."""
|
|
826
|
+
if args or None in (y, x, height, width):
|
|
827
|
+
raise TypeError("read_region takes keywords only: read_region(y=, x=, height=, "
|
|
828
|
+
"width=, **planes) (micro-reader 0.4.2; it took (x, y, width, "
|
|
829
|
+
"height) by position before)")
|
|
816
830
|
if width < 0 or height < 0:
|
|
817
831
|
raise ValueError(f"negative region size {width} x {height}")
|
|
818
|
-
ox, oy = self.
|
|
832
|
+
ox, oy = self._xy
|
|
819
833
|
ny, nx = self.shape[self.axes.index("y")], self.shape[self.axes.index("x")]
|
|
820
834
|
y0, y1 = min(max(y - oy, 0), ny), min(max(y + height - oy, 0), ny)
|
|
821
835
|
x0, x1 = min(max(x - ox, 0), nx), min(max(x + width - ox, 0), nx)
|
|
@@ -1171,7 +1185,7 @@ class _CziFile(File):
|
|
|
1171
1185
|
mine = [e for e in pyramid if self._key_of(e) == values]
|
|
1172
1186
|
if not mine:
|
|
1173
1187
|
return []
|
|
1174
|
-
x0, y0 = image.
|
|
1188
|
+
x0, y0 = image._xy
|
|
1175
1189
|
ny, nx = image.shape[image.axes.index("y")], image.shape[image.axes.index("x")]
|
|
1176
1190
|
by_zoom: dict = {}
|
|
1177
1191
|
for e in mine:
|
|
@@ -69,6 +69,7 @@ from .._io import ThreadHandles
|
|
|
69
69
|
NAME = "oir"
|
|
70
70
|
MAGIC = b"OLYMPUSRAWFORMAT"
|
|
71
71
|
RAW_TASK_BYTES = 8 << 20 # planes are read in row pieces of this size
|
|
72
|
+
SEPARATE_READ_BYTES = 32 << 10 # bytes worth skipping rather than issuing one more read
|
|
72
73
|
BLOCK_METADATA, BLOCK_FRAMEPROPERTIES, BLOCK_UID, BLOCK_PIXEL = 0, 1, 3, 4
|
|
73
74
|
UID_PATTERN = re.compile(
|
|
74
75
|
r"(?:l(\d+))?(?:z(\d+))?(?:t(\d+))?(?:_(\d+)_(\d+))?_([0-9a-f-]+)_(\d+)$")
|
|
@@ -477,7 +478,9 @@ class _OirImage(Image):
|
|
|
477
478
|
return end - start
|
|
478
479
|
|
|
479
480
|
def _read_rows(self, plane, y0, y1, xs, dst) -> int:
|
|
480
|
-
"""Rows y0:y1, columns xs of a plane into *dst* (rows, columns).
|
|
481
|
+
"""Rows y0:y1, columns xs of a plane into *dst* (rows, columns).
|
|
482
|
+
Returns the values read (more than *dst* holds when skipped columns
|
|
483
|
+
were read along)."""
|
|
481
484
|
blocks, starts = plane
|
|
482
485
|
item, row = self._file_dtype.itemsize, self._row_bytes
|
|
483
486
|
direct = NATIVE_LITTLE or item == 1
|
|
@@ -489,6 +492,17 @@ class _OirImage(Image):
|
|
|
489
492
|
self._read_range(blocks, starts, y0 * row, memoryview(buf).cast("B"))
|
|
490
493
|
dst[...] = buf
|
|
491
494
|
return dst.size
|
|
495
|
+
rows, width = y1 - y0, (xs.stop - xs.start) * item
|
|
496
|
+
if rows > 1 and row - width <= SEPARATE_READ_BYTES:
|
|
497
|
+
# a few skipped bytes per row cost less than one more read per row (a
|
|
498
|
+
# 512-column block of a 3554-column frame was 512 reads): the span from
|
|
499
|
+
# the first row's columns to the last row's, in one read (as CZI, LIF, MRC)
|
|
500
|
+
span = (rows - 1) * row + width
|
|
501
|
+
flat = np.empty(rows * row, np.uint8)
|
|
502
|
+
self._read_range(blocks, starts, y0 * row + xs.start * item,
|
|
503
|
+
memoryview(flat)[:span])
|
|
504
|
+
dst[...] = flat.reshape(rows, row)[:, :width].view(self._file_dtype)
|
|
505
|
+
return span // item
|
|
492
506
|
buf = None if direct else np.empty(xs.stop - xs.start, self._file_dtype)
|
|
493
507
|
for i, y in enumerate(range(y0, y1)):
|
|
494
508
|
target = dst[i] if direct else buf
|
|
@@ -142,7 +142,11 @@ def own_codec(key):
|
|
|
142
142
|
return None
|
|
143
143
|
codec = IMAGE_CODECS[c]
|
|
144
144
|
if codec == "jpeg" and getattr(key, "jpegheader", None):
|
|
145
|
-
|
|
145
|
+
# NDPI: header outside the segments; _decode_segment joins it to each
|
|
146
|
+
# stripe. Native when micro-reader-codecs links libjpeg-turbo (0.0.3 on):
|
|
147
|
+
# its speed and pixels, no imagecodecs. Before that tifffile + imagecodecs
|
|
148
|
+
# (micro-reader's own JPEG decoder was 1.5-1.9x slower per stripe)
|
|
149
|
+
return "jpeg" if _codecs.has_libjpeg_turbo() else None
|
|
146
150
|
if codec != "jpeg" and key.is_subsampled:
|
|
147
151
|
return None
|
|
148
152
|
return codec
|
|
@@ -1055,7 +1059,13 @@ class _TiffImage(Image):
|
|
|
1055
1059
|
_codecs.eer_decode_into(data, seg.reshape(shape[:2]), *eer_parameters(self._key))
|
|
1056
1060
|
return seg[None]
|
|
1057
1061
|
if codec == "jpeg":
|
|
1058
|
-
|
|
1062
|
+
header = getattr(self._key, "jpegheader", None)
|
|
1063
|
+
if header:
|
|
1064
|
+
# NDPI: tifffile cuts the one big JPEG at its restart markers (McuStarts)
|
|
1065
|
+
# into tiles of one restart interval; each is the shared header, its size
|
|
1066
|
+
# patched to the tile (tifffile.ndpi_jpeg_tile), + its bytes + EOI
|
|
1067
|
+
data = b"".join((header, data, b"\xff\xd9"))
|
|
1068
|
+
elif jpegtables: # abbreviated stream: tables from JPEGTables
|
|
1059
1069
|
data = bytes(jpegtables[:-2]) + bytes(data[2:])
|
|
1060
1070
|
got = _codecs.jpeg_decode_into(data, seg, colour=self._jpeg_colour)
|
|
1061
1071
|
else:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|