Cellpose#

class cellpose_omni.models.Cellpose(gpu=False, model_type='cyto', net_avg=True, device=None, use_torch=True, model_dir=None, dim=2, omni=None)[source]#

Bases: object

main model which combines SizeModel and CellposeModel

Parameters
  • gpu (bool (optional, default False)) -- whether or not to use GPU, will check if GPU available

  • model_type (str (optional, default 'cyto')) -- 'cyto'=cytoplasm model; 'nuclei'=nucleus model

  • net_avg (bool (optional, default True)) -- loads the 4 built-in networks and averages them if True, loads one network if False

  • device (gpu device (optional, default None)) -- where model is saved (e.g. mx.gpu() or mx.cpu()), overrides gpu input, recommended if you want to use a specific GPU (e.g. mx.gpu(4) or torch.cuda.device(4))

  • torch (bool (optional, default True)) -- run model using torch if available

Methods Summary

eval(x[, batch_size, channels, ...])

run cellpose and get masks

Methods Documentation

eval(x, batch_size=8, channels=None, channel_axis=None, z_axis=None, invert=False, normalize=True, diameter=30.0, do_3D=False, anisotropy=None, net_avg=True, augment=False, tile=True, tile_overlap=0.1, resample=True, interp=True, cluster=False, boundary_seg=False, affinity_seg=False, despur=True, flow_threshold=0.4, mask_threshold=0.0, cellprob_threshold=None, dist_threshold=None, diam_threshold=12.0, min_size=15, max_size=None, stitch_threshold=0.0, rescale=None, progress=None, omni=False, verbose=False, transparency=False, model_loaded=False)[source]#

run cellpose and get masks

Parameters
  • x (list or array of images) -- can be list of 2D/3D images, or array of 2D/3D images, or 4D image array

  • batch_size (int (optional, default 8)) -- number of 224x224 patches to run simultaneously on the GPU (can make smaller or bigger depending on GPU memory usage)

  • channels (list (optional, default None)) -- list of channels, either of length 2 or of length number of images by 2. First element of list is the channel to segment (0=grayscale, 1=red, 2=green, 3=blue). 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]. To segment one grayscale image and one image with cells in green and nuclei in blue, input [[0,0], [2,3]].

  • channel_axis (int (optional, default None)) -- if None, channels dimension is attempted to be automatically determined

  • z_axis (int (optional, default None)) -- if None, z dimension is attempted to be automatically determined

  • invert (bool (optional, default False)) -- invert image pixel intensity before running network (if True, image is also normalized)

  • normalize (bool (optional, default True)) -- normalize data so 0.0=1st percentile and 1.0=99th percentile of image intensities in each channel

  • diameter (float (optional, default 30.)) -- if set to None, then diameter is automatically estimated if size model is loaded

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

  • anisotropy (float (optional, default None)) -- for 3D segmentation, optional rescaling factor (e.g. set to 2.0 if Z is sampled half as dense as X or Y)

  • net_avg (bool (optional, default True)) -- runs the 4 built-in networks and averages them if True, runs one network if False

  • augment (bool (optional, default False)) -- tiles image with overlapping tiles and flips overlapped regions to augment

  • tile (bool (optional, default True)) -- tiles image to ensure GPU/CPU memory usage limited (recommended)

  • tile_overlap (float (optional, default 0.1)) -- fraction of overlap of tiles when computing flows

  • resample (bool (optional, default True)) -- run dynamics at original image size (will be slower but create more accurate boundaries)

  • interp (bool (optional, default True)) -- interpolate during 2D dynamics (not available in 3D) (in previous versions it was False)

  • flow_threshold (float (optional, default 0.4)) -- flow error threshold (all cells with errors below threshold are kept) (not used for 3D)

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

  • dist_threshold (float (optional, default None) DEPRECATED) -- use mask_threshold instead

  • cellprob_threshold (float (optional, default None) DEPRECATED) -- use mask_threshold instead

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

  • stitch_threshold (float (optional, default 0.0)) -- if stitch_threshold>0.0 and not do_3D and equal image sizes, masks are stitched in 3D to return volume segmentation

  • rescale (float (optional, default None)) -- if diameter is set to None, and rescale is not None, then rescale is used instead of diameter for resizing image

  • progress (pyqt progress bar (optional, default None)) -- to return progress bar status to GUI

  • omni (bool (optional, default False)) -- use omnipose mask recontruction features

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

  • verbose (bool (optional, default False)) -- turn on additional output to logs for debugging

  • verbose -- turn on additional output to logs for debugging

  • transparency (bool (optional, default False)) -- modulate flow opacity by magnitude instead of brightness (can use flows on any color background)

  • model_loaded (bool (optional, default False)) -- internal variable for determining if model has been loaded, used in __main__.py

Returns

  • masks (list of 2D arrays, or single 3D array (if do_3D=True)) -- labelled image, where 0=no masks; 1,2,...=mask labels

  • flows (list of lists 2D arrays, or list of 3D arrays (if do_3D=True)) -- flows[k][0] = XY flow in HSV 0-255 flows[k][1] = flows at each pixel flows[k][2] = scalar cell probability (Cellpose) or distance transform (Omnipose) flows[k][3] = final pixel locations after Euler integration flows[k][4] = boundary output (nonempty for Omnipose) flows[k][5] = pixel traces (nonempty for calc_trace=True)

  • styles (list of 1D arrays of length 256, or single 1D array (if do_3D=True)) -- style vector summarizing each image, also used to estimate size of objects in image

  • diams (list of diameters, or float (if do_3D=True))