Skip to content

Commit 0d3ea28

Browse files
committed
ENH: Add get_roi_multiscales method
1 parent f69cbec commit 0d3ea28

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

itkwidgets/viewer.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from typing import List, Union, Tuple
99
from IPython.display import display, HTML
1010
from IPython.lib import backgroundjobs as bg
11-
from ngff_zarr import from_ngff_zarr, to_ngff_image, NgffImage
11+
from ngff_zarr import (
12+
from_ngff_zarr,
13+
to_ngff_image,
14+
Multiscales,
15+
NgffImage
16+
)
1217
import uuid
1318

1419
from ._method_types import deferred_methods
@@ -434,6 +439,30 @@ async def get_roi_image(self, scale: int = -1, name: str = 'Image') -> NgffImage
434439
)
435440
raise ValueError(f'No image data found for {name}.')
436441

442+
@fetch_value
443+
async def get_roi_multiscale(self, name: str = 'Image') -> Multiscales:
444+
"""Build and return a new Multiscales NgffImage for the ROI.
445+
446+
:param name: Name of the loaded image data to use. 'Image', the
447+
default, selects the first loaded image.
448+
:type name: str
449+
450+
:return: roi_multiscales
451+
:rtype: Multiscales NgffImage
452+
"""
453+
if store := self.stores.get(name):
454+
multiscales = from_ngff_zarr(store)
455+
scales = range(len(multiscales.images))
456+
images = [await self.get_roi_image(s) for s in scales]
457+
return Multiscales(
458+
images=images,
459+
metadata=multiscales.metadata,
460+
scale_factors=multiscales.scale_factors,
461+
method=multiscales.method,
462+
chunks=multiscales.chunks
463+
)
464+
raise ValueError(f'No image data found for {name}.')
465+
437466
@fetch_value
438467
async def get_roi_region(self):
439468
"""Get the current region of interest in world / physical space.

0 commit comments

Comments
 (0)