harpy.im.cellpose_callable

harpy.im.cellpose_callable#

harpy.im.cellpose_callable(img, batch_size=8, channels=None, normalize=True, invert=False, diameter=55, flow_threshold=0.6, cellprob_threshold=0.0, do_3D=False, anisotropy=2, flow3D_smooth=0, stitch_threshold=0, min_size=80, max_size_fraction=0.4, niter=None, pretrained_model='nuclei', device=None)#

Perform cell segmentation using the Cellpose model.

Should be passed to model parameter of harpy.im.segment for distributed processing.

Parameters:
  • img (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]) – The input image as a numpy array. Dimensions should follow the format (z,y,x,c).

  • batch_size (int (default: 8)) – Number of 256x256 (cellpose>=4.0) or 224x224 (cellpose<4.0) patches to run simultaneously. (can make smaller or bigger depending on GPU/CPU/MPS memory usage). Defaults to 8.

  • channels (list[int] | None (default: None)) – List of channels. First element of list is the channel to segment. Second element of list is the optional nuclear channel (0=none, 1=red, 2=green, 3=blue). For instance, to segment grayscale images, input [0,0]. To segment images with cells in green and nuclei in blue, input [2,3]. channels is deprecated in v4.0.1+. If data contain more than 3 channels, only the first 3 channels will be used.

  • normalize (bool (default: True)) – If True, normalize data so 0.0=1st percentile and 1.0=99th percentile of image intensities in each channel. See documentation of cellpose.models.CellposeModel.eval for full description.

  • invert (bool (default: False)) – Invert image pixel intensity before running network. Defaults to False.

  • diameter (int (default: 55)) – The estimated diameter of cells (in pixels).

  • flow_threshold (float (default: 0.6)) – Flow error threshold (all cells with errors below threshold are kept) (not used for 3D). Defaults to 0.4.

  • cellprob_threshold (float (default: 0.0)) – All pixels with value above threshold kept for masks, decrease to find more and larger masks. Defaults to 0.0.

  • do_3D (bool (default: False)) – Whether to perform 3D segmentation on the input image.

  • anisotropy (float (default: 2)) – The anisotropy value (ratio of z-axis voxel size to xy voxel size) for 3D segmentation. (E.g. set to 2.0 if Z is sampled half as dense as X or Y). Ignored if do_3D is False.

  • flow3D_smooth (int (default: 0)) – If do_3D and flow3D_smooth>0, smooth flows with gaussian filter of this stddev.

  • stitch_threshold (float (default: 0)) – If stitch_threshold>0.0 and not do_3D, masks are stitched in 3D to return volume segmentation. Defaults to 0.0.

  • min_size (int (default: 80)) – The minimum size (in pixels) of segmented objects. Objects smaller than this will be excluded.

  • max_size_fraction (float (default: 0.4)) – Masks larger than max_size_fraction of total image size are removed. Default is 0.4.

  • niter (int | None (default: None)) – number of iterations for dynamics computation. if None, it is set proportional to the diameter. Defaults to None.

  • pretrained_model (str | Path (default: 'nuclei')) – A pretrained Cellpose model to use for segmentation. This can either be a model type, e.g. "nuclei", "cyto", "cyto3" for Cellpose<4.0 or "cpsam" for Cellpose >=4.0; or a file path to a saved model on disk. Default is "nuclei".

  • device (str | device | None (default: None)) – The device to run the model on. Can be "cpu", "cuda", "mps", or another supported device. If None, device will be automatically inferred, i.e. is "cuda" or "mps" if available, otherwise "cpu".

Return type:

ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]

Returns:

: A numpy array containing the segmented regions as labeled masks (z,y,x,c).

See also

harpy.im.segment

distributed segmentation using Dask.