Images API reference¶
Open an image¶
ngio.open_image
¶
open_image(
store: StoreOrGroup,
path: str | None = None,
pixel_size: PixelSize | None = None,
strict: bool = False,
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) –Select the pyramid level whose pixel size matches this one. A lookup key, not a value to write; to set a pixel size see
pixelsizeon the create/derive entry points. -
strict(bool, default:False) –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
Image¶
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
wavelength_ids
property
¶
Return the list of wavelength of the image.
has_axis
¶
set_axes_units
¶
set_axes_units(
space_unit: SpaceUnits = DefaultSpaceUnit,
time_unit: TimeUnits = DefaultTimeUnit,
) -> None
Set the space and time units of the image axes.
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
set_axes_unit
¶
set_axes_unit(
space_unit: SpaceUnits = DefaultSpaceUnit,
time_unit: TimeUnits = DefaultTimeUnit,
) -> None
Deprecated alias for set_axes_units.
Source code in src/ngio/images/_abstract_image.py
set_axes_names
¶
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
set_name
¶
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
roi
¶
roi(name: str | None = 'image') -> Roi
Return the ROI covering the entire image.
Source code in src/ngio/images/_abstract_image.py
build_image_roi_table
¶
build_image_roi_table(
name: str | None = "image",
) -> RoiTable
Build the ROI table containing the ROI covering the entire image.
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
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
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
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
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
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
get_channel_idx
¶
Get the index of a channel by its label or wavelength ID.
Source code in src/ngio/images/_image.py
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
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
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
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
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
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
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
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
consolidate
¶
consolidate(
order: InterpolationOrder = "linear",
mode: Literal["dask", "numpy", "coarsen"] = "dask",
) -> None
Consolidate the label on disk.
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 = False,
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) –Select the pyramid level whose pixel size matches this one. A lookup key, not a value to write; to set a pixel size see
pixelsizeon the create/derive entry points. -
strict(bool, default:False) –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
Label¶
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
get_roi_as_numpy
class-attribute
instance-attribute
¶
get_roi_as_numpy = AbstractImage._get_roi_as_numpy
get_roi_as_dask
class-attribute
instance-attribute
¶
get_roi_as_dask = AbstractImage._get_roi_as_dask
has_axis
¶
set_axes_units
¶
set_axes_units(
space_unit: SpaceUnits = DefaultSpaceUnit,
time_unit: TimeUnits = DefaultTimeUnit,
) -> None
Set the space and time units of the image axes.
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
set_axes_unit
¶
set_axes_unit(
space_unit: SpaceUnits = DefaultSpaceUnit,
time_unit: TimeUnits = DefaultTimeUnit,
) -> None
Deprecated alias for set_axes_units.
Source code in src/ngio/images/_abstract_image.py
set_axes_names
¶
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
set_name
¶
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
roi
¶
roi(name: str | None = 'image') -> Roi
Return the ROI covering the entire image.
Source code in src/ngio/images/_abstract_image.py
build_image_roi_table
¶
build_image_roi_table(
name: str | None = "image",
) -> RoiTable
Build the ROI table containing the ROI covering the entire image.
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
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
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
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
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
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
build_masking_roi_table
¶
build_masking_roi_table(
axes_order: Sequence[str] | None = None,
) -> MaskingRoiTable