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(default:None) Image layer in
imgthat should be processed. If None and only 1 layer is present, it will be selected.- library_id
str|Sequence[str] |None(default: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
Literal['log','dog','doh','watershed'] |SegmentationModel|Callable[...,NDArray[Any]] (default:'watershed') 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(default:0) Channel index to use for segmentation. If None, use all channels.
- chunks
str|int|tuple[int,int] |None(default:None) Number of chunks for Dask. For automatic chunking, use
chunks = 'auto'.- lazy
bool(default:False) Whether to lazily compute the result or not. Only used when
chunks != None.- layer_added
str|None(default:None) Layer of new image layer to add into
imgobject. 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(default:False) If
True, return the result, otherwise save it to the image container.- kwargs
Any Keyword arguments for the underlying model.
- img
- Returns:
ImageContainer|None– Ifcopy = 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.