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
modelparameter ofharpy.im.segmentfor distributed processing.- Parameters:
img (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The input image as anumpyarray. 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].channelsis deprecated in v4.0.1+. If data contain more than 3 channels, only the first 3 channels will be used.normalize (
bool(default:True)) – IfTrue, normalize data so 0.0=1st percentile and 1.0=99th percentile of image intensities in each channel. See documentation ofcellpose.models.CellposeModel.evalfor full description.invert (
bool(default:False)) – Invert image pixel intensity before running network. Defaults toFalse.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 ofz-axis voxel size toxyvoxel size) for 3D segmentation. (E.g. set to 2.0 if Z is sampled half as dense as X or Y). Ignored ifdo_3DisFalse.flow3D_smooth (
int(default:0)) – Ifdo_3Dandflow3D_smooth>0, smooth flows with gaussian filter of this stddev.stitch_threshold (
float(default:0)) – Ifstitch_threshold>0.0and notdo_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 thanmax_size_fractionof total image size are removed. Default is 0.4.niter (
int|None(default:None)) – number of iterations for dynamics computation. ifNone, it is set proportional to the diameter. Defaults toNone.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. IfNone, 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
numpyarray containing the segmented regions as labeled masks(z,y,x,c).
See also
harpy.im.segmentdistributed segmentation using
Dask.