labels_to_flows#

omnipose.core.labels_to_flows(labels, links=None, files=None, use_gpu=False, device=None, omni=True, redo_flows=False, dim=2)[source]#

Convert labels (list of masks or flows) to flows for training model.

if files is not None, flows are saved to files to be reused

Parameters
  • labels (list of ND-arrays) -- labels[k] can be 2D or 3D, if [3 x Ly x Lx] then it is assumed that flows were precomputed. Otherwise labels[k][0] or labels[k] (if 2D) is used to create flows.

  • links (list of label links) -- These lists of label pairs define which labels are "linked", i.e. should be treated as part of the same object. This is how Omnipose handles internal/self-contact boundaries during training.

  • files (list of strings) -- list of file names for the base images that are appended with '_flows.tif' for saving.

  • use_gpu (bool) -- flag to use GPU for speedup. Note that Omnipose fixes some bugs that caused the Cellpose GPU implementation to have different behavior compared to the Cellpose CPU implementation.

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

  • omni (bool) -- flag to generate Omnipose flows instead of Cellpose flows

  • redo_flows (bool) -- flag to overwrite existing flows. This is necessary when changing over from Cellpose to Omnipose, as the flows are very different.

  • dim (int) -- integer representing the intrinsic dimensionality of the data. This allows users to generate 3D flows for volumes. Some dependencies will need to be to be extended to allow for 4D, but the image and label loading is generalized to ND.

Returns

flows -- flows[k][0] is labels[k], flows[k][1] is cell distance transform, flows[k][2:2+dim] are the (T)YX flow components, and flows[k][-1] is heat distribution / smooth distance

Return type

list of [4 x Ly x Lx] arrays