ImageContainer.add_img

ImageContainer.add_img#

ImageContainer.add_img(img, layer=None, dims='default', library_id=None, lazy=True, chunks=None, copy=True, **kwargs)[source]#

Add a new image to the container.

Parameters:
img str | Path | NDArray[Any] | DataArray | Literal['ImageContainer']

In-memory 2, 3 or 4-dimensional array, a URL to a Zarr store (ending in .zarr), or a path to an on-disk image.

layer str | None (default: None)

Image layer in img that should be processed. If None and only 1 layer is present, it will be selected.

dims Literal['default', 'channels_last', 'z_last'] | Sequence[str] (default: 'default')

Where to save channel dimension when reading from a file or loading an array. Valid options are:

  • ’channels_last’ - load the last non-spatial dimension as channels.

  • ’z_last’ - load the last non-spatial dimension as Z-dimension.

  • ’default’ - same as ‘channels_last’, but for 4-dimensional arrays, tries to also load the first dimension as channels if the last non-spatial dimension is 1.

  • a sequence of dimension names matching the shape of img, e.g. ('y', 'x', 'z', 'channels'). ‘y’, ‘x’ and ‘z’ must always be present.

library_id str | Sequence[str] | None (default: None)

Name for each Z-dimension of the image. This should correspond to the library_id in anndata.AnnData.uns.

lazy bool (default: True)

Whether to use Dask to lazily load image.

chunks str | tuple[int, ...] | None (default: None)

Chunk size for Dask. Only used when lazy = True.

copy bool (default: True)

Whether to copy the underlying data if img is an in-memory array.

Returns:

None – Nothing, just adds a new layer to data.

Raises:
  • ValueError – If loading from a file/store with an unknown format or if a supplied channel dimension cannot be aligned.

  • NotImplementedError – If loading a specific data type has not been implemented.