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,
axes_setup: AxesSetup | None = None,
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.
-
axes_setup(AxesSetup | None, default:None) –Axes setup to load ome-zarr with non-standard axes configurations.
-
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 src/ngio/images/_ome_zarr_container.py
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 | |
ngio.Image Class Reference¶
ngio.Image
¶
Image(
group_handler: ZarrGroupHandler,
path: str,
meta_handler: ImageMetaHandler,
)
Bases: AbstractImage
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) –The image metadata handler.
Source code in src/ngio/images/_image.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
wavelength_ids
property
¶
wavelength_ids: list[str | None]
Return the list of wavelength of the image.
has_axis
¶
has_axis(axis: str) -> bool
Return True if the image has the given axis.
Source code in src/ngio/images/_abstract_image.py
220 221 222 | |
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 src/ngio/images/_abstract_image.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
set_axes_names
¶
set_axes_names(axes_names: Sequence[str]) -> None
Set the axes names of the label.
Parameters:
-
axes_names(Sequence[str]) –The axes names to set.
Source code in src/ngio/images/_abstract_image.py
239 240 241 242 243 244 245 246 247 248 | |
set_name
¶
set_name(name: str) -> None
Set the name of the image in the metadata.
This does not change the group name or any paths.
Parameters:
-
name(str) –The name of the image.
Source code in src/ngio/images/_abstract_image.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
roi
¶
roi(name: str | None = 'image') -> Roi
Return the ROI covering the entire image.
Source code in src/ngio/images/_abstract_image.py
532 533 534 535 536 537 538 539 540 541 | |
build_image_roi_table
¶
build_image_roi_table(
name: str | None = "image",
) -> RoiTable
Build the ROI table containing the ROI covering the entire image.
Source code in src/ngio/images/_abstract_image.py
543 544 545 | |
require_dimensions_match
¶
require_dimensions_match(
other: AbstractImage, allow_singleton: bool = False
) -> None
Assert that two images have matching spatial dimensions.
Parameters:
-
other(AbstractImage) –The other image to compare to.
-
allow_singleton(bool, default:False) –If True, allow singleton dimensions to be compatible with non-singleton dimensions.
Raises:
-
NgioValueError–If the images do not have compatible dimensions.
Source code in src/ngio/images/_abstract_image.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
check_if_dimensions_match
¶
check_if_dimensions_match(
other: AbstractImage, allow_singleton: bool = False
) -> bool
Check if two images have matching spatial dimensions.
Parameters:
-
other(AbstractImage) –The other image to compare to.
-
allow_singleton(bool, default:False) –If True, allow singleton dimensions to be compatible with non-singleton dimensions.
Returns:
-
bool(bool) –True if the images have matching dimensions, False otherwise.
Source code in src/ngio/images/_abstract_image.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
require_axes_match
¶
require_axes_match(other: AbstractImage) -> None
Assert that two images have compatible axes.
Parameters:
-
other(AbstractImage) –The other image to compare to.
Raises:
-
NgioValueError–If the images do not have compatible axes.
Source code in src/ngio/images/_abstract_image.py
585 586 587 588 589 590 591 592 593 594 595 596 597 | |
check_if_axes_match
¶
check_if_axes_match(other: AbstractImage) -> bool
Check if two images have compatible axes.
Parameters:
-
other(AbstractImage) –The other image to compare to.
Returns:
-
bool(bool) –True if the images have compatible axes, False otherwise.
Source code in src/ngio/images/_abstract_image.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
require_rescalable
¶
require_rescalable(other: AbstractImage) -> None
Assert that two images can be rescaled to each other.
For this to be true, the images must have the same axes, and the pixel sizes must be compatible (i.e. one can be scaled to the other).
Parameters:
-
other(AbstractImage) –The other image to compare to.
Raises:
-
NgioValueError–If the images cannot be scaled to each other.
Source code in src/ngio/images/_abstract_image.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | |
check_if_rescalable
¶
check_if_rescalable(other: AbstractImage) -> bool
Check if two images can be rescaled to each other.
For this to be true, the images must have the same axes, and the pixel sizes must be compatible (i.e. one can be scaled to the other).
Parameters:
-
other(AbstractImage) –The other image to compare to.
Returns:
-
bool(bool) –True if the images can be rescaled to each other, False otherwise.
Source code in src/ngio/images/_abstract_image.py
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
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 src/ngio/images/_image.py
171 172 173 174 175 176 177 | |
get_as_numpy
¶
get_as_numpy(
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
transforms: Sequence[TransformProtocol] | None = None,
**slicing_kwargs: slice | int | Sequence[int] | None,
) -> ndarray
Get the image as a numpy array.
Parameters:
-
channel_selection(ChannelSlicingInputType, 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(Sequence[str] | None, default:None) –The order of the axes to return the array.
-
transforms(Sequence[TransformProtocol] | None, default:None) –The transforms to apply to the array.
-
**slicing_kwargs(slice | int | Sequence[int] | None, default:{}) –The slices to get the array.
Returns:
-
ndarray–The array of the region of interest.
Source code in src/ngio/images/_image.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
get_roi_as_numpy
¶
get_roi_as_numpy(
roi: Roi,
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
transforms: Sequence[TransformProtocol] | None = None,
**slicing_kwargs: SlicingInputType,
) -> ndarray
Get the image as a numpy array for a region of interest.
Parameters:
-
roi(Roi) –The region of interest to get the array.
-
channel_selection(ChannelSlicingInputType, default:None) –Select a what subset of channels to return. If None, all channels are returned.
-
axes_order(Sequence[str] | None, default:None) –The order of the axes to return the array.
-
transforms(Sequence[TransformProtocol] | None, default:None) –The transforms to apply to the array.
-
**slicing_kwargs(SlicingInputType, default:{}) –The slices to get the array.
Returns:
-
ndarray–The array of the region of interest.
Source code in src/ngio/images/_image.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
get_as_dask
¶
get_as_dask(
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
transforms: Sequence[TransformProtocol] | None = None,
**slicing_kwargs: SlicingInputType,
) -> Array
Get the image as a dask array.
Parameters:
-
channel_selection(ChannelSlicingInputType, default:None) –Select a what subset of channels to return. If None, all channels are returned.
-
axes_order(Sequence[str] | None, default:None) –The order of the axes to return the array.
-
transforms(Sequence[TransformProtocol] | None, default:None) –The transforms to apply to the array.
-
**slicing_kwargs(SlicingInputType, default:{}) –The slices to get the array.
Returns:
-
Array–The dask array of the region of interest.
Source code in src/ngio/images/_image.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
get_roi_as_dask
¶
get_roi_as_dask(
roi: Roi,
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
transforms: Sequence[TransformProtocol] | None = None,
**slicing_kwargs: SlicingInputType,
) -> Array
Get the image as a dask array for a region of interest.
Parameters:
-
roi(Roi) –The region of interest to get the array.
-
channel_selection(ChannelSlicingInputType, default:None) –Select a what subset of channels to return. If None, all channels are returned.
-
axes_order(Sequence[str] | None, default:None) –The order of the axes to return the array.
-
transforms(Sequence[TransformProtocol] | None, default:None) –The transforms to apply to the array.
-
**slicing_kwargs(SlicingInputType, default:{}) –The slices to get the array.
Returns:
-
Array–The dask array of the region of interest.
Source code in src/ngio/images/_image.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
get_array
¶
get_array(
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
transforms: Sequence[TransformProtocol] | None = None,
mode: Literal["numpy", "dask"] = "numpy",
**slicing_kwargs: SlicingInputType,
) -> ndarray | Array
Get the image as a zarr array.
Parameters:
-
channel_selection(ChannelSlicingInputType, default:None) –Select a what subset of channels to return. If None, all channels are returned.
-
axes_order(Sequence[str] | None, default:None) –The order of the axes to return the array.
-
transforms(Sequence[TransformProtocol] | None, default:None) –The transforms to apply to the array.
-
mode(Literal['numpy', 'dask'], default:'numpy') –The object type to return. Can be "dask", "numpy".
-
**slicing_kwargs(SlicingInputType, default:{}) –The slices to get the array.
Returns:
-
ndarray | Array–The zarr array of the region of interest.
Source code in src/ngio/images/_image.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
get_roi
¶
get_roi(
roi: Roi,
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
transforms: Sequence[TransformProtocol] | None = None,
mode: Literal["numpy", "dask"] = "numpy",
**slicing_kwargs: SlicingInputType,
) -> ndarray | Array
Get the image as a zarr array for a region of interest.
Parameters:
-
roi(Roi) –The region of interest to get the array.
-
channel_selection(ChannelSlicingInputType, default:None) –Select a what subset of channels to return. If None, all channels are returned.
-
axes_order(Sequence[str] | None, default:None) –The order of the axes to return the array.
-
transforms(Sequence[TransformProtocol] | None, default:None) –The transforms to apply to the array.
-
mode(Literal['numpy', 'dask'], default:'numpy') –The object type to return. Can be "dask", "numpy".
-
**slicing_kwargs(SlicingInputType, default:{}) –The slices to get the array.
Returns:
-
ndarray | Array–The zarr array of the region of interest.
Source code in src/ngio/images/_image.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
set_array
¶
set_array(
patch: ndarray | Array,
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
transforms: Sequence[TransformProtocol] | None = None,
**slicing_kwargs: SlicingInputType,
) -> None
Set the image array.
Parameters:
-
patch(ndarray | Array) –The array to set.
-
channel_selection(ChannelSlicingInputType, default:None) –Select a what subset of channels to return. If None, all channels are set.
-
axes_order(Sequence[str] | None, default:None) –The order of the axes to set the array.
-
transforms(Sequence[TransformProtocol] | None, default:None) –The transforms to apply to the array.
-
**slicing_kwargs(SlicingInputType, default:{}) –The slices to set the array.
Source code in src/ngio/images/_image.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
set_roi
¶
set_roi(
roi: Roi,
patch: ndarray | Array,
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
transforms: Sequence[TransformProtocol] | None = None,
**slicing_kwargs: SlicingInputType,
) -> None
Set the image array for a region of interest.
Parameters:
-
roi(Roi) –The region of interest to set the array.
-
patch(ndarray | Array) –The array to set.
-
channel_selection(ChannelSlicingInputType, default:None) –Select a what subset of channels to return.
-
axes_order(Sequence[str] | None, default:None) –The order of the axes to set the array.
-
transforms(Sequence[TransformProtocol] | None, default:None) –The transforms to apply to the array.
-
**slicing_kwargs(SlicingInputType, default:{}) –The slices to set the array.
Source code in src/ngio/images/_image.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
consolidate
¶
consolidate(
order: InterpolationOrder = "linear",
mode: Literal["dask", "numpy", "coarsen"] = "dask",
) -> None
Consolidate the label on disk.
Source code in src/ngio/images/_image.py
408 409 410 411 412 413 414 | |
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,
axes_setup: AxesSetup | None = None,
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.
-
axes_setup(AxesSetup | None, default:None) –Axes setup to load ome-zarr with non-standard axes configurations.
-
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 src/ngio/images/_ome_zarr_container.py
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 | |
ngio.Label Class Reference¶
ngio.Label
¶
Label(
group_handler: ZarrGroupHandler,
path: str,
meta_handler: LabelMetaHandler,
)
Bases: AbstractImage
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) –The image metadata handler.
Source code in src/ngio/images/_label.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
has_axis
¶
has_axis(axis: str) -> bool
Return True if the image has the given axis.
Source code in src/ngio/images/_abstract_image.py
220 221 222 | |
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 src/ngio/images/_abstract_image.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
set_axes_names
¶
set_axes_names(axes_names: Sequence[str]) -> None
Set the axes names of the label.
Parameters:
-
axes_names(Sequence[str]) –The axes names to set.
Source code in src/ngio/images/_abstract_image.py
239 240 241 242 243 244 245 246 247 248 | |
set_name
¶
set_name(name: str) -> None
Set the name of the image in the metadata.
This does not change the group name or any paths.
Parameters:
-
name(str) –The name of the image.
Source code in src/ngio/images/_abstract_image.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
roi
¶
roi(name: str | None = 'image') -> Roi
Return the ROI covering the entire image.
Source code in src/ngio/images/_abstract_image.py
532 533 534 535 536 537 538 539 540 541 | |
build_image_roi_table
¶
build_image_roi_table(
name: str | None = "image",
) -> RoiTable
Build the ROI table containing the ROI covering the entire image.
Source code in src/ngio/images/_abstract_image.py
543 544 545 | |
require_dimensions_match
¶
require_dimensions_match(
other: AbstractImage, allow_singleton: bool = False
) -> None
Assert that two images have matching spatial dimensions.
Parameters:
-
other(AbstractImage) –The other image to compare to.
-
allow_singleton(bool, default:False) –If True, allow singleton dimensions to be compatible with non-singleton dimensions.
Raises:
-
NgioValueError–If the images do not have compatible dimensions.
Source code in src/ngio/images/_abstract_image.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
check_if_dimensions_match
¶
check_if_dimensions_match(
other: AbstractImage, allow_singleton: bool = False
) -> bool
Check if two images have matching spatial dimensions.
Parameters:
-
other(AbstractImage) –The other image to compare to.
-
allow_singleton(bool, default:False) –If True, allow singleton dimensions to be compatible with non-singleton dimensions.
Returns:
-
bool(bool) –True if the images have matching dimensions, False otherwise.
Source code in src/ngio/images/_abstract_image.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
require_axes_match
¶
require_axes_match(other: AbstractImage) -> None
Assert that two images have compatible axes.
Parameters:
-
other(AbstractImage) –The other image to compare to.
Raises:
-
NgioValueError–If the images do not have compatible axes.
Source code in src/ngio/images/_abstract_image.py
585 586 587 588 589 590 591 592 593 594 595 596 597 | |
check_if_axes_match
¶
check_if_axes_match(other: AbstractImage) -> bool
Check if two images have compatible axes.
Parameters:
-
other(AbstractImage) –The other image to compare to.
Returns:
-
bool(bool) –True if the images have compatible axes, False otherwise.
Source code in src/ngio/images/_abstract_image.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
require_rescalable
¶
require_rescalable(other: AbstractImage) -> None
Assert that two images can be rescaled to each other.
For this to be true, the images must have the same axes, and the pixel sizes must be compatible (i.e. one can be scaled to the other).
Parameters:
-
other(AbstractImage) –The other image to compare to.
Raises:
-
NgioValueError–If the images cannot be scaled to each other.
Source code in src/ngio/images/_abstract_image.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | |
check_if_rescalable
¶
check_if_rescalable(other: AbstractImage) -> bool
Check if two images can be rescaled to each other.
For this to be true, the images must have the same axes, and the pixel sizes must be compatible (i.e. one can be scaled to the other).
Parameters:
-
other(AbstractImage) –The other image to compare to.
Returns:
-
bool(bool) –True if the images can be rescaled to each other, False otherwise.
Source code in src/ngio/images/_abstract_image.py
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
build_masking_roi_table
¶
build_masking_roi_table(
axes_order: Sequence[str] | None = None,
) -> MaskingRoiTable
Compute the masking ROI table.
Source code in src/ngio/images/_label.py
80 81 82 83 84 | |
consolidate
¶
consolidate(
mode: Literal["dask", "numpy", "coarsen"] = "dask",
) -> None
Consolidate the label on disk.
Source code in src/ngio/images/_label.py
86 87 88 89 90 91 92 93 94 | |