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_idname. For not mentionedlibrary_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 anumpy.ndarrayas input and produces an image-like output.- layer
str|None(default:None) Image layer in
imgthat 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 inlayer.- channel
int|None(default:None) Apply
funconly over a specificchannel. If None, use all channels.- chunks
str|tuple[int,int] |None(default:None) - 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 whencopy = True.- fn_kwargs
Mapping[str,Any] (default:mappingproxy({})) Keyword arguments for
func.- kwargs
Any Keyword arguments for
dask.array.map_overlap()ordask.array.map_blocks(), depending whetherdepthis present infn_kwargs. Only used whenchunks != None. Usedepthto control boundary artifacts iffuncrequires data from neighboring chunks, by default,boundary = 'reflectis used.
- func
- Returns:
ImageContainer|None– Ifcopy = True, returns a new container withlayer.- Raises:
ValueError – If the
funcreturns 0 or 1 dimensional array.