ImageContainer.apply

ImageContainer.apply#

ImageContainer.apply(func, layer=None, new_layer=None, channel=None, lazy=False, chunks=None, copy=True, drop=True, fn_kwargs=mappingproxy({}), **kwargs)[source]#

Apply a function to a layer within this container.

For each Z-dimension a different function can be defined, using its library_id name. For not mentioned library_id’s the identity function is applied.

Parameters:
func Callable[..., NDArray[Any]] | Mapping[str, Callable[..., NDArray[Any]]]

A function or a mapping of {'{library_id}': function} which takes a numpy.ndarray as input and produces an image-like output.

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.

new_layer str | None (default: None)

Name of the new layer. If None and copy = False, overwrites the data in layer.

channel int | None (default: None)

Apply func only over a specific channel. If None, use all channels.

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

Chunk size for Dask. If None, don’t use Dask.

copy bool (default: True)

If True, return the result, otherwise save it to the image container.

drop bool (default: True)

Whether to drop Z-dimensions that were not selected by func. Only used when copy = True.

fn_kwargs Mapping[str, Any] (default: mappingproxy({}))

Keyword arguments for func.

kwargs Any

Keyword arguments for dask.array.map_overlap() or dask.array.map_blocks(), depending whether depth is present in fn_kwargs. Only used when chunks != None. Use depth to control boundary artifacts if func requires data from neighboring chunks, by default, boundary = 'reflect is used.

Returns:

ImageContainer | None – If copy = True, returns a new container with layer.

Raises:

ValueError – If the func returns 0 or 1 dimensional array.