squidpy.im.segment
- squidpy.im.segment(img, layer=None, library_id=None, method='watershed', channel=0, chunks=None, lazy=False, layer_added=None, copy=False, **kwargs)[source]
Segment an image.
- Parameters:
img (
ImageContainer) – High-resolution image.layer (
str|None) – Image layer inimgthat should be processed. If None and only 1 layer is present, it will be selected.library_id (
str|Sequence[str] |None) – Name of the Z-dimension(s) that this function should be applied to. For not specified Z-dimensions, the identity function is applied. If None, all Z-dimensions are segmented separately.method (
str|SegmentationModel|Callable[...,ndarray[tuple[Any,...],dtype[Any]]]) –Segmentation method to use. Valid options are:
’watershed’ -
skimage.segmentation.watershed().
Alternatively, any
callable()can be passed as long as it has the following signature:numpy.ndarray(height, width, channels)->numpy.ndarray(height, width[, channels]).channel (
int|None) – Channel index to use for segmentation. If None, use all channels.chunks (
str|int|tuple[int,int] |None) – Number of chunks for Dask. For automatic chunking, usechunks = 'auto'.lazy (
bool) – Whether to lazily compute the result or not. Only used whenchunks != None.layer_added (
str|None) – Layer of new image layer to add intoimgobject. If None, use'segmented_{model}'.thresh – Threshold for creation of masked image. The areas to segment should be contained in this mask. If None, it is determined by Otsu’s method. Only used if
method = 'watershed'.geq – Treat
threshas upper or lower bound for defining areas to segment. Ifgeq = True, mask is defined asmask = arr >= thresh, meaning high values inarrdenote areas to segment. Only used ifmethod = 'watershed'.copy (
bool) – IfTrue, return the result, otherwise save it to the image container.kwargs (
Any) – Keyword arguments for the underlying model.
- Return type:
- Returns:
If
copy = True, returns a new container with the segmented image in'{layer_added}'.Otherwise, modifies the
imgwith the following key:squidpy.im.ImageContainer['{layer_added}']- the segmented image.