compute_masks#

omnipose.core.compute_masks(dP, dist, affinity_graph=None, bd=None, p=None, coords=None, iscell=None, niter=None, rescale=1.0, resize=None, mask_threshold=0.0, diam_threshold=12.0, flow_threshold=0.4, interp=True, cluster=False, boundary_seg=False, affinity_seg=False, do_3D=False, min_size=None, max_size=None, hole_size=None, omni=True, calc_trace=False, verbose=False, use_gpu=False, device=None, nclasses=2, dim=2, eps=None, hdbscan=False, flow_factor=6, debug=False, override=False, suppress=None, despur=True)[source]#

Compute masks using dynamics from dP, dist, and boundary outputs. Called in cellpose.models().

Parameters
  • dP (float, ND array) -- flow field components (2D: 2 x Ly x Lx, 3D: 3 x Lz x Ly x Lx)

  • dist (float, ND array) -- distance field (Ly x Lx)

  • bd (float, ND array) -- boundary field

  • p (float32, ND array) -- initial locations of each pixel before dynamics, size [axis x Ly x Lx] or [axis x Lz x Ly x Lx].

  • coords (int32, 2D array) -- non-zero pixels to run dynamics on [npixels x D]

  • niter (int32) -- number of iterations of dynamics to run

  • rescale (float (optional, default None)) -- resize factor for each image, if None, set to 1.0

  • resize (int, tuple) -- shape of array (alternative to rescaling)

  • mask_threshold (float) -- all pixels with value above threshold kept for masks, decrease to find more and larger masks

  • flow_threshold (float) -- flow error threshold (all cells with errors below threshold are kept) (not used for Cellpose3D)

  • interp (bool) -- interpolate during dynamics

  • cluster (bool) -- use sub-pixel DBSCAN clustering of pixel coordinates to find masks

  • do_3D (bool (optional, default False)) -- set to True to run 3D segmentation on 4D image input

  • min_size (int (optional, default 15)) -- minimum number of pixels per mask, can turn off with -1

  • omni (bool) -- use omnipose mask recontruction features

  • calc_trace (bool) -- calculate pixel traces and return as part of the flow

  • verbose (bool) -- turn on additional output to logs for debugging

  • use_gpu (bool) -- use GPU of flow_threshold>0 (computes flows from predicted masks on GPU)

  • device (torch device) -- what compute hardware to use to run the code (GPU VS CPU)

  • nclasses -- number of output classes of the network (Omnipose=3,Cellpose=2)

  • dim (int) -- dimensionality of data / model output

  • eps (float) -- internal epsilon parameter for (H)DBSCAN

  • hdbscan -- use better, but much SLOWER, hdbscan clustering algorithm (experimental)

  • flow_factor -- multiple to increase flow magnitude (used in 3D only, experimental)

  • debug -- option to return list of unique mask labels as a fourth output (for debugging only)

Returns

  • mask (int, ND array) -- label matrix

  • p (float32, ND array) -- final locations of each pixel after dynamics, size [axis x Ly x Lx] or [axis x Lz x Ly x Lx].

  • tr (float32, ND array) -- intermediate locations of each pixel during dynamics, size [axis x niter x Ly x Lx] or [axis x niter x Lz x Ly x Lx]. For debugging/paper figures, very slow.

  • bd (float32, ND array) -- boundary map

  • augmented_affinity (float32, ND array) -- concatenated coordinates and affinity graph, hence (d+1,3**d,npix)