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.

  • func (Union[Callable[..., ndarray[Any, dtype[Any]]], Mapping[str, Callable[..., ndarray[Any, dtype[Any]]]]]) – A function or a mapping of {'{library_id}': function} which takes a numpy.ndarray as input and produces an image-like output.

  • layer (Optional[str]) – Image layer in img that should be processed. If None and only 1 layer is present, it will be selected.

  • new_layer (Optional[str]) – Name of the new layer. If None and copy = False, overwrites the data in layer.

  • channel (Optional[int]) – Apply func only over a specific channel. If None, use all channels.

  • chunks (Union[str, tuple[int, int], None]) – Chunk size for dask. If None, don’t use dask.

  • copy (bool) – If True, return the result, otherwise save it to the image container.

  • drop (bool) – Whether to drop Z-dimensions that were not selected by func. Only used when copy = True.

  • fn_kwargs (Mapping[str, Any]) – 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.

Return type:

ImageContainer | None


: If copy = True, returns a new container with layer.


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