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 (
Optional
[str
]) – Image layer inimg
that should be processed. If None and only 1 layer is present, it will be selected.library_id (
Union
[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 (
Union
[str
,SegmentationModel
,Callable
[...
,ndarray
[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 (
Union
[str
,int
,tuple
[int
,int
],None
]) – Number of chunks fordask
. For automatic chunking, usechunks = 'auto'
.lazy (
bool
) – Whether to lazily compute the result or not. Only used whenchunks != None
.layer_added (
Optional
[str
]) – Layer of new image layer to add intoimg
object. 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
thresh
as upper or lower bound for defining areas to segment. Ifgeq = True
, mask is defined asmask = arr >= thresh
, meaning high values inarr
denote 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
img
with the following key:squidpy.im.ImageContainer
['{layer_added}']
- the segmented image.