Iterators API reference¶
ImageProcessingIterator¶
ngio.iterators.ImageProcessingIterator
¶
ImageProcessingIterator(
input_image: Image,
output_image: Image,
input_channel_selection: ChannelSlicingInputType = None,
output_channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
input_transforms: Sequence[TransformProtocol]
| None = None,
output_transforms: Sequence[TransformProtocol]
| None = None,
)
Bases: AbstractIteratorBuilder[ndarray, Array]
Base class for iterators over ROIs.
Initialize the iterator with a ROI table and input/output images.
Parameters:
-
input_image(Image) –The input image to be used as input for the segmentation.
-
output_image(Image) –The image where the ROIs will be written.
-
input_channel_selection(ChannelSlicingInputType, default:None) –Optional selection of channels to use for the input image.
-
output_channel_selection(ChannelSlicingInputType, default:None) –Optional selection of channels to use for the output image.
-
axes_order(Sequence[str] | None, default:None) –Optional axes order for the segmentation.
-
input_transforms(Sequence[TransformProtocol] | None, default:None) –Optional transforms to apply to the input image.
-
output_transforms(Sequence[TransformProtocol] | None, default:None) –Optional transforms to apply to the output label.
Source code in src/ngio/iterators/_image_processing.py
grid
¶
grid(
size_x: int | None = None,
size_y: int | None = None,
size_z: int | None = None,
size_t: int | None = None,
stride_x: int | None = None,
stride_y: int | None = None,
stride_z: int | None = None,
stride_t: int | None = None,
base_name: str = "",
) -> Self
Create a grid of ROIs based on the input image dimensions.
Source code in src/ngio/iterators/_abstract_iterator.py
by_yx
¶
Return a new iterator that iterates over ROIs by YX coordinates.
by_zyx
¶
Return a new iterator that iterates over ROIs by ZYX coordinates.
Parameters:
-
strict(bool, default:True) –If True, only iterate over ZYX if a Z axis is present and not of size 1.
Source code in src/ngio/iterators/_abstract_iterator.py
by_chunks
¶
Return a new iterator that iterates over ROIs by chunks.
Parameters:
-
overlap_xy(int, default:0) –Overlap in XY dimensions.
-
overlap_z(int, default:0) –Overlap in Z dimension.
Returns:
-
SegmentationIterator(Self) –A new iterator with chunked ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
product
¶
product(other: list[Roi] | GenericRoiTable) -> Self
Cartesian product of the current ROIs with an arbitrary list of ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
iter
¶
iter(
lazy: Literal[True],
data_mode: Literal["numpy"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[
DataGetterProtocol[NumpyPipeType],
DataSetterProtocol[NumpyPipeType],
]
]
iter(
lazy: Literal[True],
data_mode: Literal["numpy"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[DataGetterProtocol[NumpyPipeType]]
iter(
lazy: Literal[True],
data_mode: Literal["dask"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[
DataGetterProtocol[DaskPipeType],
DataSetterProtocol[DaskPipeType],
]
]
iter(
lazy: Literal[True],
data_mode: Literal["dask"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[DataGetterProtocol[DaskPipeType]]
iter(
lazy: Literal[False],
data_mode: Literal["numpy"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[NumpyPipeType, DataSetterProtocol[NumpyPipeType]]
]
iter(
lazy: Literal[False],
data_mode: Literal["numpy"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[NumpyPipeType]
iter(
lazy: bool = False,
data_mode: Literal["numpy", "dask"] = "dask",
iterator_mode: Literal[
"readwrite", "readonly"
] = "readwrite",
) -> Generator
Create an iterator over the pixels of the ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
iter_as_numpy
¶
iter_as_dask
¶
map_as_numpy
¶
map_as_numpy(
func: Callable[[NumpyPipeType], NumpyPipeType],
mapper: MapperProtocol[NumpyPipeType] | None = None,
) -> None
Apply a transformation function to the ROI pixels.
Source code in src/ngio/iterators/_abstract_iterator.py
map_as_dask
¶
map_as_dask(
func: Callable[[DaskPipeType], DaskPipeType],
mapper: MapperProtocol[DaskPipeType] | None = None,
) -> None
Apply a transformation function to the ROI pixels.
Source code in src/ngio/iterators/_abstract_iterator.py
check_if_regions_overlap
¶
Check if any of the ROIs overlap logically.
If two ROIs cover the same pixel, they are considered to overlap. This does not consider chunking or other storage details.
Returns:
-
bool(bool) –True if any ROIs overlap. False otherwise.
Source code in src/ngio/iterators/_abstract_iterator.py
require_no_regions_overlap
¶
check_if_chunks_overlap
¶
Check if any of the ROIs overlap in terms of chunks.
If two ROIs cover the same chunk, they are considered to overlap in chunks. This does not consider pixel-level overlaps.
Returns:
-
bool(bool) –True if any ROIs overlap in chunks, False otherwise.
Source code in src/ngio/iterators/_abstract_iterator.py
require_no_chunks_overlap
¶
Ensure that the ROIs do not overlap in terms of chunks.
get_init_kwargs
¶
Return the initialization arguments for the iterator.
Source code in src/ngio/iterators/_image_processing.py
build_numpy_getter
¶
build_numpy_getter(roi: Roi) -> DataGetterProtocol[ndarray]
Source code in src/ngio/iterators/_image_processing.py
build_numpy_setter
¶
build_numpy_setter(roi: Roi) -> DataSetterProtocol[ndarray]
Source code in src/ngio/iterators/_image_processing.py
build_dask_getter
¶
build_dask_getter(roi: Roi) -> DataGetterProtocol[Array]
Source code in src/ngio/iterators/_image_processing.py
SegmentationIterator¶
ngio.iterators.SegmentationIterator
¶
SegmentationIterator(
input_image: Image,
output_label: Label,
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
input_transforms: Sequence[TransformProtocol]
| None = None,
output_transforms: Sequence[TransformProtocol]
| None = None,
)
Bases: AbstractIteratorBuilder[ndarray, Array]
Base class for iterators over ROIs.
Initialize the iterator with a ROI table and input/output images.
Parameters:
-
input_image(Image) –The input image to be used as input for the segmentation.
-
output_label(Label) –The label image where the ROIs will be written.
-
channel_selection(ChannelSlicingInputType, default:None) –Optional selection of channels to use for the segmentation.
-
axes_order(Sequence[str] | None, default:None) –Optional axes order for the segmentation.
-
input_transforms(Sequence[TransformProtocol] | None, default:None) –Optional transforms to apply to the input image.
-
output_transforms(Sequence[TransformProtocol] | None, default:None) –Optional transforms to apply to the output label.
Source code in src/ngio/iterators/_segmentation.py
grid
¶
grid(
size_x: int | None = None,
size_y: int | None = None,
size_z: int | None = None,
size_t: int | None = None,
stride_x: int | None = None,
stride_y: int | None = None,
stride_z: int | None = None,
stride_t: int | None = None,
base_name: str = "",
) -> Self
Create a grid of ROIs based on the input image dimensions.
Source code in src/ngio/iterators/_abstract_iterator.py
by_yx
¶
Return a new iterator that iterates over ROIs by YX coordinates.
by_zyx
¶
Return a new iterator that iterates over ROIs by ZYX coordinates.
Parameters:
-
strict(bool, default:True) –If True, only iterate over ZYX if a Z axis is present and not of size 1.
Source code in src/ngio/iterators/_abstract_iterator.py
by_chunks
¶
Return a new iterator that iterates over ROIs by chunks.
Parameters:
-
overlap_xy(int, default:0) –Overlap in XY dimensions.
-
overlap_z(int, default:0) –Overlap in Z dimension.
Returns:
-
SegmentationIterator(Self) –A new iterator with chunked ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
product
¶
product(other: list[Roi] | GenericRoiTable) -> Self
Cartesian product of the current ROIs with an arbitrary list of ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
iter
¶
iter(
lazy: Literal[True],
data_mode: Literal["numpy"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[
DataGetterProtocol[NumpyPipeType],
DataSetterProtocol[NumpyPipeType],
]
]
iter(
lazy: Literal[True],
data_mode: Literal["numpy"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[DataGetterProtocol[NumpyPipeType]]
iter(
lazy: Literal[True],
data_mode: Literal["dask"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[
DataGetterProtocol[DaskPipeType],
DataSetterProtocol[DaskPipeType],
]
]
iter(
lazy: Literal[True],
data_mode: Literal["dask"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[DataGetterProtocol[DaskPipeType]]
iter(
lazy: Literal[False],
data_mode: Literal["numpy"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[NumpyPipeType, DataSetterProtocol[NumpyPipeType]]
]
iter(
lazy: Literal[False],
data_mode: Literal["numpy"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[NumpyPipeType]
iter(
lazy: bool = False,
data_mode: Literal["numpy", "dask"] = "dask",
iterator_mode: Literal[
"readwrite", "readonly"
] = "readwrite",
) -> Generator
Create an iterator over the pixels of the ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
iter_as_numpy
¶
iter_as_dask
¶
map_as_numpy
¶
map_as_numpy(
func: Callable[[NumpyPipeType], NumpyPipeType],
mapper: MapperProtocol[NumpyPipeType] | None = None,
) -> None
Apply a transformation function to the ROI pixels.
Source code in src/ngio/iterators/_abstract_iterator.py
map_as_dask
¶
map_as_dask(
func: Callable[[DaskPipeType], DaskPipeType],
mapper: MapperProtocol[DaskPipeType] | None = None,
) -> None
Apply a transformation function to the ROI pixels.
Source code in src/ngio/iterators/_abstract_iterator.py
check_if_regions_overlap
¶
Check if any of the ROIs overlap logically.
If two ROIs cover the same pixel, they are considered to overlap. This does not consider chunking or other storage details.
Returns:
-
bool(bool) –True if any ROIs overlap. False otherwise.
Source code in src/ngio/iterators/_abstract_iterator.py
require_no_regions_overlap
¶
check_if_chunks_overlap
¶
Check if any of the ROIs overlap in terms of chunks.
If two ROIs cover the same chunk, they are considered to overlap in chunks. This does not consider pixel-level overlaps.
Returns:
-
bool(bool) –True if any ROIs overlap in chunks, False otherwise.
Source code in src/ngio/iterators/_abstract_iterator.py
require_no_chunks_overlap
¶
Ensure that the ROIs do not overlap in terms of chunks.
get_init_kwargs
¶
Return the initialization arguments for the iterator.
Source code in src/ngio/iterators/_segmentation.py
build_numpy_getter
¶
build_numpy_getter(roi: Roi) -> DataGetterProtocol[ndarray]
Source code in src/ngio/iterators/_segmentation.py
build_numpy_setter
¶
build_numpy_setter(roi: Roi) -> DataSetterProtocol[ndarray]
Source code in src/ngio/iterators/_segmentation.py
build_dask_getter
¶
build_dask_getter(roi: Roi) -> DataGetterProtocol[Array]
Source code in src/ngio/iterators/_segmentation.py
MaskedSegmentationIterator¶
ngio.iterators.MaskedSegmentationIterator
¶
MaskedSegmentationIterator(
input_image: MaskedImage,
output_label: Label,
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
input_transforms: Sequence[TransformProtocol]
| None = None,
output_transforms: Sequence[TransformProtocol]
| None = None,
)
Bases: SegmentationIterator
Base class for iterators over ROIs.
Initialize the iterator with a ROI table and input/output images.
Parameters:
-
input_image(MaskedImage) –The input image to be used as input for the segmentation.
-
output_label(Label) –The label image where the ROIs will be written.
-
channel_selection(ChannelSlicingInputType, default:None) –Optional selection of channels to use for the segmentation.
-
axes_order(Sequence[str] | None, default:None) –Optional axes order for the segmentation.
-
input_transforms(Sequence[TransformProtocol] | None, default:None) –Optional transforms to apply to the input image.
-
output_transforms(Sequence[TransformProtocol] | None, default:None) –Optional transforms to apply to the output label.
Source code in src/ngio/iterators/_segmentation.py
grid
¶
grid(
size_x: int | None = None,
size_y: int | None = None,
size_z: int | None = None,
size_t: int | None = None,
stride_x: int | None = None,
stride_y: int | None = None,
stride_z: int | None = None,
stride_t: int | None = None,
base_name: str = "",
) -> Self
Create a grid of ROIs based on the input image dimensions.
Source code in src/ngio/iterators/_abstract_iterator.py
by_yx
¶
Return a new iterator that iterates over ROIs by YX coordinates.
by_zyx
¶
Return a new iterator that iterates over ROIs by ZYX coordinates.
Parameters:
-
strict(bool, default:True) –If True, only iterate over ZYX if a Z axis is present and not of size 1.
Source code in src/ngio/iterators/_abstract_iterator.py
by_chunks
¶
Return a new iterator that iterates over ROIs by chunks.
Parameters:
-
overlap_xy(int, default:0) –Overlap in XY dimensions.
-
overlap_z(int, default:0) –Overlap in Z dimension.
Returns:
-
SegmentationIterator(Self) –A new iterator with chunked ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
product
¶
product(other: list[Roi] | GenericRoiTable) -> Self
Cartesian product of the current ROIs with an arbitrary list of ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
iter
¶
iter(
lazy: Literal[True],
data_mode: Literal["numpy"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[
DataGetterProtocol[NumpyPipeType],
DataSetterProtocol[NumpyPipeType],
]
]
iter(
lazy: Literal[True],
data_mode: Literal["numpy"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[DataGetterProtocol[NumpyPipeType]]
iter(
lazy: Literal[True],
data_mode: Literal["dask"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[
DataGetterProtocol[DaskPipeType],
DataSetterProtocol[DaskPipeType],
]
]
iter(
lazy: Literal[True],
data_mode: Literal["dask"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[DataGetterProtocol[DaskPipeType]]
iter(
lazy: Literal[False],
data_mode: Literal["numpy"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[NumpyPipeType, DataSetterProtocol[NumpyPipeType]]
]
iter(
lazy: Literal[False],
data_mode: Literal["numpy"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[NumpyPipeType]
iter(
lazy: bool = False,
data_mode: Literal["numpy", "dask"] = "dask",
iterator_mode: Literal[
"readwrite", "readonly"
] = "readwrite",
) -> Generator
Create an iterator over the pixels of the ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
iter_as_numpy
¶
iter_as_dask
¶
map_as_numpy
¶
map_as_numpy(
func: Callable[[NumpyPipeType], NumpyPipeType],
mapper: MapperProtocol[NumpyPipeType] | None = None,
) -> None
Apply a transformation function to the ROI pixels.
Source code in src/ngio/iterators/_abstract_iterator.py
map_as_dask
¶
map_as_dask(
func: Callable[[DaskPipeType], DaskPipeType],
mapper: MapperProtocol[DaskPipeType] | None = None,
) -> None
Apply a transformation function to the ROI pixels.
Source code in src/ngio/iterators/_abstract_iterator.py
check_if_regions_overlap
¶
Check if any of the ROIs overlap logically.
If two ROIs cover the same pixel, they are considered to overlap. This does not consider chunking or other storage details.
Returns:
-
bool(bool) –True if any ROIs overlap. False otherwise.
Source code in src/ngio/iterators/_abstract_iterator.py
require_no_regions_overlap
¶
check_if_chunks_overlap
¶
Check if any of the ROIs overlap in terms of chunks.
If two ROIs cover the same chunk, they are considered to overlap in chunks. This does not consider pixel-level overlaps.
Returns:
-
bool(bool) –True if any ROIs overlap in chunks, False otherwise.
Source code in src/ngio/iterators/_abstract_iterator.py
require_no_chunks_overlap
¶
Ensure that the ROIs do not overlap in terms of chunks.
get_init_kwargs
¶
Return the initialization arguments for the iterator.
Source code in src/ngio/iterators/_segmentation.py
build_numpy_getter
¶
build_numpy_getter(roi: Roi)
Source code in src/ngio/iterators/_segmentation.py
build_numpy_setter
¶
build_numpy_setter(roi: Roi)
Source code in src/ngio/iterators/_segmentation.py
build_dask_getter
¶
build_dask_getter(roi: Roi)
Source code in src/ngio/iterators/_segmentation.py
build_dask_setter
¶
build_dask_setter(roi: Roi)
Source code in src/ngio/iterators/_segmentation.py
FeatureExtractorIterator¶
ngio.iterators.FeatureExtractorIterator
¶
FeatureExtractorIterator(
input_image: Image,
input_label: Label,
channel_selection: ChannelSlicingInputType = None,
axes_order: Sequence[str] | None = None,
input_transforms: Sequence[TransformProtocol]
| None = None,
label_transforms: Sequence[TransformProtocol]
| None = None,
)
Bases: AbstractIteratorBuilder[NumpyPipeType, DaskPipeType]
Base class for iterators over ROIs.
Initialize the iterator with a ROI table and input/output images.
Parameters:
-
input_image(Image) –The input image to be used as input for the segmentation.
-
input_label(Label) –The input label with the segmentation masks.
-
channel_selection(ChannelSlicingInputType, default:None) –Optional selection of channels to use for the segmentation.
-
axes_order(Sequence[str] | None, default:None) –Optional axes order for the segmentation.
-
input_transforms(Sequence[TransformProtocol] | None, default:None) –Optional transforms to apply to the input image.
-
label_transforms(Sequence[TransformProtocol] | None, default:None) –Optional transforms to apply to the output label.
Source code in src/ngio/iterators/_feature.py
grid
¶
grid(
size_x: int | None = None,
size_y: int | None = None,
size_z: int | None = None,
size_t: int | None = None,
stride_x: int | None = None,
stride_y: int | None = None,
stride_z: int | None = None,
stride_t: int | None = None,
base_name: str = "",
) -> Self
Create a grid of ROIs based on the input image dimensions.
Source code in src/ngio/iterators/_abstract_iterator.py
by_yx
¶
Return a new iterator that iterates over ROIs by YX coordinates.
by_zyx
¶
Return a new iterator that iterates over ROIs by ZYX coordinates.
Parameters:
-
strict(bool, default:True) –If True, only iterate over ZYX if a Z axis is present and not of size 1.
Source code in src/ngio/iterators/_abstract_iterator.py
by_chunks
¶
Return a new iterator that iterates over ROIs by chunks.
Parameters:
-
overlap_xy(int, default:0) –Overlap in XY dimensions.
-
overlap_z(int, default:0) –Overlap in Z dimension.
Returns:
-
SegmentationIterator(Self) –A new iterator with chunked ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
product
¶
product(other: list[Roi] | GenericRoiTable) -> Self
Cartesian product of the current ROIs with an arbitrary list of ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
iter
¶
iter(
lazy: Literal[True],
data_mode: Literal["numpy"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[
DataGetterProtocol[NumpyPipeType],
DataSetterProtocol[NumpyPipeType],
]
]
iter(
lazy: Literal[True],
data_mode: Literal["numpy"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[DataGetterProtocol[NumpyPipeType]]
iter(
lazy: Literal[True],
data_mode: Literal["dask"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[
DataGetterProtocol[DaskPipeType],
DataSetterProtocol[DaskPipeType],
]
]
iter(
lazy: Literal[True],
data_mode: Literal["dask"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[DataGetterProtocol[DaskPipeType]]
iter(
lazy: Literal[False],
data_mode: Literal["numpy"],
iterator_mode: Literal["readwrite"],
) -> Generator[
tuple[NumpyPipeType, DataSetterProtocol[NumpyPipeType]]
]
iter(
lazy: Literal[False],
data_mode: Literal["numpy"],
iterator_mode: Literal["readonly"] = ...,
) -> Generator[NumpyPipeType]
iter(
lazy: bool = False,
data_mode: Literal["numpy", "dask"] = "dask",
iterator_mode: Literal[
"readwrite", "readonly"
] = "readwrite",
) -> Generator
Create an iterator over the pixels of the ROIs.
Source code in src/ngio/iterators/_abstract_iterator.py
map_as_numpy
¶
map_as_numpy(
func: Callable[[NumpyPipeType], NumpyPipeType],
mapper: MapperProtocol[NumpyPipeType] | None = None,
) -> None
Apply a transformation function to the ROI pixels.
Source code in src/ngio/iterators/_abstract_iterator.py
map_as_dask
¶
map_as_dask(
func: Callable[[DaskPipeType], DaskPipeType],
mapper: MapperProtocol[DaskPipeType] | None = None,
) -> None
Apply a transformation function to the ROI pixels.
Source code in src/ngio/iterators/_abstract_iterator.py
check_if_regions_overlap
¶
Check if any of the ROIs overlap logically.
If two ROIs cover the same pixel, they are considered to overlap. This does not consider chunking or other storage details.
Returns:
-
bool(bool) –True if any ROIs overlap. False otherwise.
Source code in src/ngio/iterators/_abstract_iterator.py
require_no_regions_overlap
¶
check_if_chunks_overlap
¶
Check if any of the ROIs overlap in terms of chunks.
If two ROIs cover the same chunk, they are considered to overlap in chunks. This does not consider pixel-level overlaps.
Returns:
-
bool(bool) –True if any ROIs overlap in chunks, False otherwise.
Source code in src/ngio/iterators/_abstract_iterator.py
require_no_chunks_overlap
¶
Ensure that the ROIs do not overlap in terms of chunks.
get_init_kwargs
¶
Return the initialization arguments for the iterator.
Source code in src/ngio/iterators/_feature.py
build_numpy_getter
¶
build_numpy_getter(roi: Roi) -> NumpyFeatureGetter
Source code in src/ngio/iterators/_feature.py
build_dask_getter
¶
build_dask_getter(roi: Roi) -> DaskFeatureGetter