Skip to content

Images Like: API Documentation

Open an Image

ngio.open_image

open_image(
    store: StoreOrGroup,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = True,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
) -> Image

Open a single level image from an OME-Zarr image.

Parameters:

  • store (StoreOrGroup) –

    The Zarr store or group to create the image in.

  • path (str | None, default: None ) –

    The path to the image in the ome_zarr file.

  • pixel_size (PixelSize | None, default: None ) –

    The pixel size of the image.

  • strict (bool, default: True ) –

    Only used if the pixel size is provided. If True, the pixel size must match the image pixel size exactly. If False, the closest pixel size level will be returned.

  • cache (bool, default: False ) –

    Whether to use a cache for the zarr group metadata.

  • mode (AccessModeLiteral, default: 'r+' ) –

    The access mode for the image. Defaults to "r+".

Source code in ngio/images/_ome_zarr_container.py
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
def open_image(
    store: StoreOrGroup,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = True,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
) -> Image:
    """Open a single level image from an OME-Zarr image.

    Args:
        store (StoreOrGroup): The Zarr store or group to create the image in.
        path (str | None): The path to the image in the ome_zarr file.
        pixel_size (PixelSize | None): The pixel size of the image.
        strict (bool): Only used if the pixel size is provided. If True, the
                pixel size must match the image pixel size exactly. If False, the
                closest pixel size level will be returned.
        cache (bool): Whether to use a cache for the zarr group metadata.
        mode (AccessModeLiteral): The
            access mode for the image. Defaults to "r+".
    """
    group_handler = ZarrGroupHandler(store, cache, mode)
    images_container = ImagesContainer(group_handler)
    return images_container.get(
        path=path,
        pixel_size=pixel_size,
        strict=strict,
    )

ngio.Image Class Reference

ngio.Image

Image(
    group_handler: ZarrGroupHandler,
    path: str,
    meta_handler: ImageMetaHandler | None,
)

Bases: AbstractImage[ImageMetaHandler]

A class to handle a single image (or level) in an OME-Zarr image.

This class is meant to be subclassed by specific image types.

Initialize the Image at a single level.

Parameters:

  • group_handler (ZarrGroupHandler) –

    The Zarr group handler.

  • path (str) –

    The path to the image in the ome_zarr file.

  • meta_handler (ImageMetaHandler | None) –

    The image metadata handler.

Source code in ngio/images/_image.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def __init__(
    self,
    group_handler: ZarrGroupHandler,
    path: str,
    meta_handler: ImageMetaHandler | None,
) -> None:
    """Initialize the Image at a single level.

    Args:
        group_handler: The Zarr group handler.
        path: The path to the image in the ome_zarr file.
        meta_handler: The image metadata handler.

    """
    if meta_handler is None:
        meta_handler = find_image_meta_handler(group_handler)
    super().__init__(
        group_handler=group_handler, path=path, meta_handler=meta_handler
    )

meta_handler property

meta_handler: _image_handler

Return the metadata.

zarr_array property

zarr_array: Array

Return the Zarr array.

shape property

shape: tuple[int, ...]

Return the shape of the image.

dtype property

dtype: str

Return the dtype of the image.

chunks property

chunks: tuple[int, ...]

Return the chunks of the image.

dimensions property

dimensions: Dimensions

Return the dimensions of the image.

axes_mapper property

axes_mapper: AxesMapper

Return the axes mapper of the image.

is_3d property

is_3d: bool

Return True if the image is 3D.

is_2d property

is_2d: bool

Return True if the image is 2D.

is_time_series property

is_time_series: bool

Return True if the image is a time series.

is_2d_time_series property

is_2d_time_series: bool

Return True if the image is a 2D time series.

is_3d_time_series property

is_3d_time_series: bool

Return True if the image is a 3D time series.

is_multi_channels property

is_multi_channels: bool

Return True if the image is multichannel.

space_unit property

space_unit: str | None

Return the space unit of the image.

time_unit property

time_unit: str | None

Return the time unit of the image.

pixel_size property

pixel_size: PixelSize

Return the pixel size of the image.

dataset property

dataset: Dataset

Return the dataset of the image.

path property

path: str

Return the path of the image.

meta property

meta: NgioImageMeta

Return the metadata.

channels_meta property

channels_meta: ChannelsMeta

Return the channels metadata.

channel_labels property

channel_labels: list[str]

Return the channels of the image.

wavelength_ids property

wavelength_ids: list[str | None]

Return the list of wavelength of the image.

num_channels property

num_channels: int

Return the number of channels.

has_axis

has_axis(axis: str) -> bool

Return True if the image has the given axis.

Source code in ngio/images/_abstract_image.py
171
172
173
174
def has_axis(self, axis: str) -> bool:
    """Return True if the image has the given axis."""
    self.axes_mapper.get_index("x")
    return self.dimensions.has_axis(axis)

build_image_roi_table

build_image_roi_table(name: str = 'image') -> RoiTable

Build the ROI table for an image.

Source code in ngio/images/_abstract_image.py
472
473
474
def build_image_roi_table(self, name: str = "image") -> RoiTable:
    """Build the ROI table for an image."""
    return build_image_roi_table(image=self, name=name)

get_channel_idx

get_channel_idx(
    channel_label: str | None = None,
    wavelength_id: str | None = None,
) -> int

Get the index of a channel by its label or wavelength ID.

Source code in ngio/images/_image.py
103
104
105
106
107
108
109
def get_channel_idx(
    self, channel_label: str | None = None, wavelength_id: str | None = None
) -> int:
    """Get the index of a channel by its label or wavelength ID."""
    return self.channels_meta.get_channel_idx(
        channel_label=channel_label, wavelength_id=wavelength_id
    )

get_as_numpy

get_as_numpy(
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> ndarray

Get the image as a numpy array.

Parameters:

  • channel_label (str | None, default: None ) –

    Select a specific channel by label. If None, all channels are returned. Alternatively, you can slice arbitrary channels using the slice_kwargs (c=[0, 2]).

  • axes_order (Collection[str] | None, default: None ) –

    The order of the axes to return the array.

  • transforms (Collection[TransformProtocol] | None, default: None ) –

    The transforms to apply to the array.

  • **slice_kwargs (slice | int | Iterable[int], default: {} ) –

    The slices to get the array.

Returns:

  • ndarray

    The array of the region of interest.

Source code in ngio/images/_image.py
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
def get_as_numpy(
    self,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> np.ndarray:
    """Get the image as a numpy array.

    Args:
        channel_label: Select a specific channel by label.
            If None, all channels are returned.
            Alternatively, you can slice arbitrary channels
            using the slice_kwargs (c=[0, 2]).
        axes_order: The order of the axes to return the array.
        transforms: The transforms to apply to the array.
        **slice_kwargs: The slices to get the array.

    Returns:
        The array of the region of interest.
    """
    slice_kwargs = self._add_channel_label(
        channel_label=channel_label, **slice_kwargs
    )
    return self._get_as_numpy(
        axes_order=axes_order, transforms=transforms, **slice_kwargs
    )

get_roi_as_numpy

get_roi_as_numpy(
    roi: Roi | RoiPixels,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> ndarray

Get the image as a numpy array for a region of interest.

Parameters:

  • roi (Roi | RoiPixels) –

    The region of interest to get the array.

  • channel_label (str | None, default: None ) –

    Select a specific channel by label. If None, all channels are returned. Alternatively, you can slice arbitrary channels using the slice_kwargs (c=[0, 2]).

  • axes_order (Collection[str] | None, default: None ) –

    The order of the axes to return the array.

  • transforms (Collection[TransformProtocol] | None, default: None ) –

    The transforms to apply to the array.

  • **slice_kwargs (slice | int | Iterable[int], default: {} ) –

    The slices to get the array.

Returns:

  • ndarray

    The array of the region of interest.

Source code in ngio/images/_image.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
def get_roi_as_numpy(
    self,
    roi: Roi | RoiPixels,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> np.ndarray:
    """Get the image as a numpy array for a region of interest.

    Args:
        roi: The region of interest to get the array.
        channel_label: Select a specific channel by label.
            If None, all channels are returned.
            Alternatively, you can slice arbitrary channels
            using the slice_kwargs (c=[0, 2]).
        axes_order: The order of the axes to return the array.
        transforms: The transforms to apply to the array.
        **slice_kwargs: The slices to get the array.

    Returns:
        The array of the region of interest.
    """
    slice_kwargs = self._add_channel_label(
        channel_label=channel_label, **slice_kwargs
    )
    return self._get_roi_as_numpy(
        roi=roi, axes_order=axes_order, transforms=transforms, **slice_kwargs
    )

get_as_dask

get_as_dask(
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> Array

Get the image as a dask array.

Parameters:

  • channel_label (str | None, default: None ) –

    Select a specific channel by label. If None, all channels are returned. Alternatively, you can slice arbitrary channels using the slice_kwargs (c=[0, 2]).

  • axes_order (Collection[str] | None, default: None ) –

    The order of the axes to return the array.

  • transforms (Collection[TransformProtocol] | None, default: None ) –

    The transforms to apply to the array.

  • **slice_kwargs (slice | int | Iterable[int], default: {} ) –

    The slices to get the array.

Returns:

  • Array

    The dask array of the region of interest.

Source code in ngio/images/_image.py
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def get_as_dask(
    self,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> da.Array:
    """Get the image as a dask array.

    Args:
        channel_label: Select a specific channel by label.
            If None, all channels are returned.
            Alternatively, you can slice arbitrary channels
            using the slice_kwargs (c=[0, 2]).
        axes_order: The order of the axes to return the array.
        transforms: The transforms to apply to the array.
        **slice_kwargs: The slices to get the array.

    Returns:
        The dask array of the region of interest.
    """
    slice_kwargs = self._add_channel_label(
        channel_label=channel_label, **slice_kwargs
    )
    return self._get_as_dask(
        axes_order=axes_order, transforms=transforms, **slice_kwargs
    )

get_roi_as_dask

get_roi_as_dask(
    roi: Roi | RoiPixels,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> Array

Get the image as a dask array for a region of interest.

Parameters:

  • roi (Roi | RoiPixels) –

    The region of interest to get the array.

  • channel_label (str | None, default: None ) –

    Select a specific channel by label. If None, all channels are returned. Alternatively, you can slice arbitrary channels using the slice_kwargs (c=[0, 2]).

  • axes_order (Collection[str] | None, default: None ) –

    The order of the axes to return the array.

  • transforms (Collection[TransformProtocol] | None, default: None ) –

    The transforms to apply to the array.

  • **slice_kwargs (slice | int | Iterable[int], default: {} ) –

    The slices to get the array.

Returns:

  • Array

    The dask array of the region of interest.

Source code in ngio/images/_image.py
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
def get_roi_as_dask(
    self,
    roi: Roi | RoiPixels,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> da.Array:
    """Get the image as a dask array for a region of interest.

    Args:
        roi: The region of interest to get the array.
        channel_label: Select a specific channel by label.
            If None, all channels are returned.
            Alternatively, you can slice arbitrary channels
            using the slice_kwargs (c=[0, 2]).
        axes_order: The order of the axes to return the array.
        transforms: The transforms to apply to the array.
        **slice_kwargs: The slices to get the array.

    Returns:
        The dask array of the region of interest.
    """
    slice_kwargs = self._add_channel_label(
        channel_label=channel_label, **slice_kwargs
    )
    return self._get_roi_as_dask(
        roi=roi, axes_order=axes_order, transforms=transforms, **slice_kwargs
    )

get_as_delayed

get_as_delayed(
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> Delayed

Get the image as a dask delayed array.

Parameters:

  • channel_label (str | None, default: None ) –

    Select a specific channel by label. If None, all channels are returned. Alternatively, you can slice arbitrary channels using the slice_kwargs (c=[0, 2]).

  • axes_order (Collection[str] | None, default: None ) –

    The order of the axes to return the array.

  • transforms (Collection[TransformProtocol] | None, default: None ) –

    The transforms to apply to the array.

  • **slice_kwargs (slice | int | Iterable[int], default: {} ) –

    The slices to get the array.

Returns:

  • Delayed

    The dask delayed array of the region of interest.

Source code in ngio/images/_image.py
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
def get_as_delayed(
    self,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> Delayed:
    """Get the image as a dask delayed array.

    Args:
        channel_label: Select a specific channel by label.
            If None, all channels are returned.
            Alternatively, you can slice arbitrary channels
            using the slice_kwargs (c=[0, 2]).
        axes_order: The order of the axes to return the array.
        transforms: The transforms to apply to the array.
        **slice_kwargs: The slices to get the array.

    Returns:
        The dask delayed array of the region of interest.
    """
    slice_kwargs = self._add_channel_label(
        channel_label=channel_label, **slice_kwargs
    )
    return self._get_as_delayed(
        axes_order=axes_order, transforms=transforms, **slice_kwargs
    )

get_roi_as_delayed

get_roi_as_delayed(
    roi: Roi | RoiPixels,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> Delayed

Get the image as a dask delayed array for a region of interest.

Parameters:

  • roi (Roi | RoiPixels) –

    The region of interest to get the array.

  • channel_label (str | None, default: None ) –

    Select a specific channel by label. If None, all channels are returned. Alternatively, you can slice arbitrary channels using the slice_kwargs (c=[0, 2]).

  • axes_order (Collection[str] | None, default: None ) –

    The order of the axes to return the array.

  • transforms (Collection[TransformProtocol] | None, default: None ) –

    The transforms to apply to the array.

  • **slice_kwargs (slice | int | Iterable[int], default: {} ) –

    The slices to get the array.

Returns:

  • Delayed

    The dask delayed array of the region of interest.

Source code in ngio/images/_image.py
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
def get_roi_as_delayed(
    self,
    roi: Roi | RoiPixels,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> Delayed:
    """Get the image as a dask delayed array for a region of interest.

    Args:
        roi: The region of interest to get the array.
        channel_label: Select a specific channel by label.
            If None, all channels are returned.
            Alternatively, you can slice arbitrary channels
            using the slice_kwargs (c=[0, 2]).
        axes_order: The order of the axes to return the array.
        transforms: The transforms to apply to the array.
        **slice_kwargs: The slices to get the array.

    Returns:
        The dask delayed array of the region of interest.
    """
    slice_kwargs = self._add_channel_label(
        channel_label=channel_label, **slice_kwargs
    )
    return self._get_roi_as_delayed(
        roi=roi, axes_order=axes_order, transforms=transforms, **slice_kwargs
    )

get_array

get_array(
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    mode: Literal["numpy", "dask", "delayed"] = "numpy",
    **slice_kwargs: slice | int | Iterable[int],
) -> ArrayLike

Get the image as a zarr array.

Parameters:

  • channel_label (str | None, default: None ) –

    Select a specific channel by label. If None, all channels are returned. Alternatively, you can slice arbitrary channels using the slice_kwargs (c=[0, 2]).

  • axes_order (Collection[str] | None, default: None ) –

    The order of the axes to return the array.

  • transforms (Collection[TransformProtocol] | None, default: None ) –

    The transforms to apply to the array.

  • mode (Literal['numpy', 'dask', 'delayed'], default: 'numpy' ) –

    The object type to return. Can be "dask", "numpy", or "delayed".

  • **slice_kwargs (slice | int | Iterable[int], default: {} ) –

    The slices to get the array.

Returns:

  • ArrayLike

    The zarr array of the region of interest.

Source code in ngio/images/_image.py
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
def get_array(
    self,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    mode: Literal["numpy", "dask", "delayed"] = "numpy",
    **slice_kwargs: slice | int | Iterable[int],
) -> ArrayLike:
    """Get the image as a zarr array.

    Args:
        channel_label: Select a specific channel by label.
            If None, all channels are returned.
            Alternatively, you can slice arbitrary channels
            using the slice_kwargs (c=[0, 2]).
        axes_order: The order of the axes to return the array.
        transforms: The transforms to apply to the array.
        mode: The object type to return.
            Can be "dask", "numpy", or "delayed".
        **slice_kwargs: The slices to get the array.

    Returns:
        The zarr array of the region of interest.
    """
    slice_kwargs = self._add_channel_label(
        channel_label=channel_label, **slice_kwargs
    )
    return self._get_array(
        axes_order=axes_order, mode=mode, transforms=transforms, **slice_kwargs
    )

get_roi

get_roi(
    roi: Roi | RoiPixels,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    mode: Literal["numpy", "dask", "delayed"] = "numpy",
    **slice_kwargs: slice | int | Iterable[int],
) -> ArrayLike

Get the image as a zarr array for a region of interest.

Parameters:

  • roi (Roi | RoiPixels) –

    The region of interest to get the array.

  • channel_label (str | None, default: None ) –

    Select a specific channel by label. If None, all channels are returned. Alternatively, you can slice arbitrary channels using the slice_kwargs (c=[0, 2]).

  • axes_order (Collection[str] | None, default: None ) –

    The order of the axes to return the array.

  • transforms (Collection[TransformProtocol] | None, default: None ) –

    The transforms to apply to the array.

  • mode (Literal['numpy', 'dask', 'delayed'], default: 'numpy' ) –

    The object type to return. Can be "dask", "numpy", or "delayed".

  • **slice_kwargs (slice | int | Iterable[int], default: {} ) –

    The slices to get the array.

Returns:

  • ArrayLike

    The zarr array of the region of interest.

Source code in ngio/images/_image.py
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
def get_roi(
    self,
    roi: Roi | RoiPixels,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    mode: Literal["numpy", "dask", "delayed"] = "numpy",
    **slice_kwargs: slice | int | Iterable[int],
) -> ArrayLike:
    """Get the image as a zarr array for a region of interest.

    Args:
        roi: The region of interest to get the array.
        channel_label: Select a specific channel by label.
            If None, all channels are returned.
            Alternatively, you can slice arbitrary channels
            using the slice_kwargs (c=[0, 2]).
        axes_order: The order of the axes to return the array.
        transforms: The transforms to apply to the array.
        mode: The object type to return.
            Can be "dask", "numpy", or "delayed".
        **slice_kwargs: The slices to get the array.

    Returns:
        The zarr array of the region of interest.
    """
    slice_kwargs = self._add_channel_label(
        channel_label=channel_label, **slice_kwargs
    )
    return self._get_roi(
        roi=roi,
        axes_order=axes_order,
        mode=mode,
        transforms=transforms,
        **slice_kwargs,
    )

set_array

set_array(
    patch: ArrayLike,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> None

Set the image array.

Parameters:

  • patch (ArrayLike) –

    The array to set.

  • channel_label (str | None, default: None ) –

    Select a specific channel by label. If None, all channels are set. Alternatively, you can slice arbitrary channels using the slice_kwargs (c=[0, 2]).

  • axes_order (Collection[str] | None, default: None ) –

    The order of the axes to set the array.

  • transforms (Collection[TransformProtocol] | None, default: None ) –

    The transforms to apply to the array.

  • **slice_kwargs (slice | int | Iterable[int], default: {} ) –

    The slices to set the array.

Source code in ngio/images/_image.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
def set_array(
    self,
    patch: ArrayLike,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> None:
    """Set the image array.

    Args:
        patch: The array to set.
        channel_label: Select a specific channel by label.
            If None, all channels are set.
            Alternatively, you can slice arbitrary channels
            using the slice_kwargs (c=[0, 2]).
        axes_order: The order of the axes to set the array.
        transforms: The transforms to apply to the array.
        **slice_kwargs: The slices to set the array.
    """
    slice_kwargs = self._add_channel_label(
        channel_label=channel_label, **slice_kwargs
    )
    self._set_array(
        patch=patch, axes_order=axes_order, transforms=transforms, **slice_kwargs
    )

set_roi

set_roi(
    roi: Roi | RoiPixels,
    patch: ArrayLike,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> None

Set the image array for a region of interest.

Parameters:

  • roi (Roi | RoiPixels) –

    The region of interest to set the array.

  • patch (ArrayLike) –

    The array to set.

  • channel_label (str | None, default: None ) –

    Select a specific channel by label. If None, all channels are set. Alternatively, you can slice arbitrary channels using the slice_kwargs (c=[0, 2]).

  • axes_order (Collection[str] | None, default: None ) –

    The order of the axes to set the array.

  • transforms (Collection[TransformProtocol] | None, default: None ) –

    The transforms to apply to the array.

  • **slice_kwargs (slice | int | Iterable[int], default: {} ) –

    The slices to set the array.

Source code in ngio/images/_image.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
def set_roi(
    self,
    roi: Roi | RoiPixels,
    patch: ArrayLike,
    channel_label: str | None = None,
    axes_order: Collection[str] | None = None,
    transforms: Collection[TransformProtocol] | None = None,
    **slice_kwargs: slice | int | Iterable[int],
) -> None:
    """Set the image array for a region of interest.

    Args:
        roi: The region of interest to set the array.
        patch: The array to set.
        channel_label: Select a specific channel by label.
            If None, all channels are set.
            Alternatively, you can slice arbitrary channels
            using the slice_kwargs (c=[0, 2]).
        axes_order: The order of the axes to set the array.
        transforms: The transforms to apply to the array.
        **slice_kwargs: The slices to set the array.
    """
    slice_kwargs = self._add_channel_label(
        channel_label=channel_label, **slice_kwargs
    )
    self._set_roi(
        roi=roi,
        patch=patch,
        axes_order=axes_order,
        transforms=transforms,
        **slice_kwargs,
    )

consolidate

consolidate(
    order: Literal[0, 1, 2] = 1,
    mode: Literal["dask", "numpy", "coarsen"] = "dask",
) -> None

Consolidate the label on disk.

Source code in ngio/images/_image.py
429
430
431
432
433
434
435
def consolidate(
    self,
    order: Literal[0, 1, 2] = 1,
    mode: Literal["dask", "numpy", "coarsen"] = "dask",
) -> None:
    """Consolidate the label on disk."""
    self._consolidate(order=order, mode=mode)

Open a Label

ngio.open_label

open_label(
    store: StoreOrGroup,
    name: str | None = None,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = True,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
) -> Label

Open a single level label from an OME-Zarr Label group.

Parameters:

  • store (StoreOrGroup) –

    The Zarr store or group to create the image in.

  • name (str | None, default: None ) –

    The name of the label. If None, we will try to open the store as a multiscale label.

  • path (str | None, default: None ) –

    The path to the image in the ome_zarr file.

  • pixel_size (PixelSize | None, default: None ) –

    The pixel size of the image.

  • strict (bool, default: True ) –

    Only used if the pixel size is provided. If True, the pixel size must match the image pixel size exactly. If False, the closest pixel size level will be returned.

  • cache (bool, default: False ) –

    Whether to use a cache for the zarr group metadata.

  • mode (AccessModeLiteral, default: 'r+' ) –

    The access mode for the image. Defaults to "r+".

Source code in ngio/images/_ome_zarr_container.py
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
def open_label(
    store: StoreOrGroup,
    name: str | None = None,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = True,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
) -> Label:
    """Open a single level label from an OME-Zarr Label group.

    Args:
        store (StoreOrGroup): The Zarr store or group to create the image in.
        name (str | None): The name of the label. If None,
            we will try to open the store as a multiscale label.
        path (str | None): The path to the image in the ome_zarr file.
        pixel_size (PixelSize | None): The pixel size of the image.
        strict (bool): Only used if the pixel size is provided. If True, the
            pixel size must match the image pixel size exactly. If False, the
            closest pixel size level will be returned.
        cache (bool): Whether to use a cache for the zarr group metadata.
        mode (AccessModeLiteral): The access mode for the image. Defaults to "r+".

    """
    group_handler = ZarrGroupHandler(store, cache, mode)
    if name is None:
        label_meta_handler = find_label_meta_handler(group_handler)
        path = label_meta_handler.meta.get_dataset(
            path=path, pixel_size=pixel_size, strict=strict
        ).path
        return Label(group_handler, path, label_meta_handler)

    labels_container = LabelsContainer(group_handler)
    return labels_container.get(
        name=name,
        path=path,
        pixel_size=pixel_size,
        strict=strict,
    )

ngio.Label Class Reference

ngio.Label

Label(
    group_handler: ZarrGroupHandler,
    path: str,
    meta_handler: LabelMetaHandler | None,
)

Bases: AbstractImage[LabelMetaHandler]

Placeholder class for a label.

Initialize the Image at a single level.

Parameters:

  • group_handler (ZarrGroupHandler) –

    The Zarr group handler.

  • path (str) –

    The path to the image in the ome_zarr file.

  • meta_handler (LabelMetaHandler | None) –

    The image metadata handler.

Source code in ngio/images/_label.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def __init__(
    self,
    group_handler: ZarrGroupHandler,
    path: str,
    meta_handler: LabelMetaHandler | None,
) -> None:
    """Initialize the Image at a single level.

    Args:
        group_handler: The Zarr group handler.
        path: The path to the image in the ome_zarr file.
        meta_handler: The image metadata handler.

    """
    if meta_handler is None:
        meta_handler = find_label_meta_handler(group_handler)
    super().__init__(
        group_handler=group_handler, path=path, meta_handler=meta_handler
    )

meta_handler property

meta_handler: _image_handler

Return the metadata.

zarr_array property

zarr_array: Array

Return the Zarr array.

shape property

shape: tuple[int, ...]

Return the shape of the image.

dtype property

dtype: str

Return the dtype of the image.

chunks property

chunks: tuple[int, ...]

Return the chunks of the image.

dimensions property

dimensions: Dimensions

Return the dimensions of the image.

axes_mapper property

axes_mapper: AxesMapper

Return the axes mapper of the image.

is_3d property

is_3d: bool

Return True if the image is 3D.

is_2d property

is_2d: bool

Return True if the image is 2D.

is_time_series property

is_time_series: bool

Return True if the image is a time series.

is_2d_time_series property

is_2d_time_series: bool

Return True if the image is a 2D time series.

is_3d_time_series property

is_3d_time_series: bool

Return True if the image is a 3D time series.

is_multi_channels property

is_multi_channels: bool

Return True if the image is multichannel.

space_unit property

space_unit: str | None

Return the space unit of the image.

time_unit property

time_unit: str | None

Return the time unit of the image.

pixel_size property

pixel_size: PixelSize

Return the pixel size of the image.

dataset property

dataset: Dataset

Return the dataset of the image.

path property

path: str

Return the path of the image.

get_as_numpy class-attribute instance-attribute

get_as_numpy = _get_as_numpy

get_as_dask class-attribute instance-attribute

get_as_dask = _get_as_dask

get_as_delayed class-attribute instance-attribute

get_as_delayed = _get_as_delayed

get_array class-attribute instance-attribute

get_array = _get_array

get_roi_as_numpy class-attribute instance-attribute

get_roi_as_numpy = _get_roi_as_numpy

get_roi_as_dask class-attribute instance-attribute

get_roi_as_dask = _get_roi_as_dask

get_roi_as_delayed class-attribute instance-attribute

get_roi_as_delayed = _get_roi_as_delayed

get_roi class-attribute instance-attribute

get_roi = _get_roi

set_array class-attribute instance-attribute

set_array = _set_array

set_roi class-attribute instance-attribute

set_roi = _set_roi

meta property

meta: NgioLabelMeta

Return the metadata.

has_axis

has_axis(axis: str) -> bool

Return True if the image has the given axis.

Source code in ngio/images/_abstract_image.py
171
172
173
174
def has_axis(self, axis: str) -> bool:
    """Return True if the image has the given axis."""
    self.axes_mapper.get_index("x")
    return self.dimensions.has_axis(axis)

build_image_roi_table

build_image_roi_table(name: str = 'image') -> RoiTable

Build the ROI table for an image.

Source code in ngio/images/_abstract_image.py
472
473
474
def build_image_roi_table(self, name: str = "image") -> RoiTable:
    """Build the ROI table for an image."""
    return build_image_roi_table(image=self, name=name)

set_axes_unit

set_axes_unit(
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
) -> None

Set the axes unit of the image.

Parameters:

  • space_unit (SpaceUnits, default: DefaultSpaceUnit ) –

    The space unit of the image.

  • time_unit (TimeUnits, default: DefaultTimeUnit ) –

    The time unit of the image.

Source code in ngio/images/_label.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def set_axes_unit(
    self,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
) -> None:
    """Set the axes unit of the image.

    Args:
        space_unit (SpaceUnits): The space unit of the image.
        time_unit (TimeUnits): The time unit of the image.
    """
    meta = self.meta
    meta = meta.to_units(space_unit=space_unit, time_unit=time_unit)
    self._meta_handler.write_meta(meta)

build_masking_roi_table

build_masking_roi_table() -> MaskingRoiTable

Compute the masking ROI table.

Source code in ngio/images/_label.py
89
90
91
def build_masking_roi_table(self) -> MaskingRoiTable:
    """Compute the masking ROI table."""
    return build_masking_roi_table(self)

consolidate

consolidate(
    mode: Literal["dask", "numpy", "coarsen"] = "dask",
) -> None

Consolidate the label on disk.

Source code in ngio/images/_label.py
 93
 94
 95
 96
 97
 98
 99
100
101
def consolidate(
    self,
    mode: Literal["dask", "numpy", "coarsen"] = "dask",
) -> None:
    """Consolidate the label on disk."""
    self._consolidate(
        order=0,
        mode=mode,
    )