masks_to_flows#
- omnipose.core.masks_to_flows(masks, affinity_graph=None, dists=None, coords=None, links=None, use_gpu=True, device=None, omni=True, dim=2, smooth=False, normalize=False, n_iter=None, verbose=False)[source]#
Convert masks to flows.
First, we find the scalar field. In Omnipose, this is the distance field. In Cellpose, this is diffusion from center pixel. Center of masks where diffusion starts is defined to be the closest pixel to the median of all pixels that is inside the mask.
The flow components are then found as hthe gradient of the scalar field.
- Parameters
masks (int, ND array) -- labeled masks, 0 = background, 1,2,...,N = mask labels
dists (ND array, float) -- array of (nonnegative) distance field values
affinity_graph (ND array, bool) -- hypervoxel affinity array, alternative to providing overseg labels and links the most general way to compute flows, and can represent internal boundaries
links (list of label links) -- list of tuples used for treating label pairs as the same
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
dim (int) -- dimensionality of image data
- Returns
mu (float, 3D or 4D array) -- flows in Y = mu[-2], flows in X = mu[-1]. if masks are 3D, flows in Z = mu[0].
mu_c (float, 2D or 3D array) -- for each pixel, the distance to the center of the mask in which it resides