omnipose.core

affinity_to_boundary(masks, affinity_graph, ...)

Convert affinity graph to boundary map.

affinity_to_masks(affinity_graph, ...[, ...])

Convert affinity graph to label matrix using connected components.

affinity_to_masks2(affinity_graph, ...[, ...])

Faster replacement for affinity_to_masks using union-find.

batch_labels(masks, bd, T, mu, tyx, dim, ...)

boundary_to_affinity(masks, boundaries)

This function converts boundary+interior labels to an affinity graph.

boundary_to_masks(boundaries[, binary_mask, ...])

compute_masks(dP, dist[, affinity_graph, ...])

Compute masks using dynamics from dP, dist, and boundary outputs.

concatenate_labels(masks, links, nsample)

diameters(masks[, dt, dist_threshold, pill, ...])

Calculate the mean cell diameter from a label matrix.

dist_to_diam(dt_pos, n)

Convert positive distance field values to a mean diameter.

div_rescale(dP, mask[, p])

Normalize the flow magnitude to rescaled 0-1 divergence.

divergence(f[, sp])

Computes divergence of vector field

divergence_torch(y)

Divergence for a batched D-vector field stored as (B, D, *spatial).

divergence_torch_old(y)

do_warp(A, M_inv, tyx[, offset, order, mode])

Wrapper function for affine transformations during augmentation.

fill_holes_and_remove_small_masks(masks[, ...])

fill holes in masks (2D/3D) and discard masks smaller than min_size (2D)

flow_error(maski, dP_net[, coords, ...])

error in flows from predicted masks vs flows predicted by network run on image

follow_flows(dP, dist, inds[, niter, ...])

define pixels and run dynamics to recover masks in 2D

get_boundary(mu, mask[, bd, affinity_graph, ...])

One way to get boundaries by considering flow dot products.

get_contour(labels, affinity_graph[, ...])

Sort 2D boundaries into cyclic paths.

get_link_matrix(links, piece_masks, inds, ...)

Public wrapper: convert an iterable of (a,b) link tuples into a 2D array and call the jitted helper.

get_links(masks, labels, bd[, connectivity])

get_masks(p, bd, dist, mask, inds[, ...])

Omnipose mask recontruction algorithm.

get_masks_cp(p[, iscell, rpad, flows, ...])

create masks using pixel convergence after running dynamics

get_niter(dists)

Get number of iterations.

labels_to_flows(labels[, links, files, ...])

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

linker_label_to_links(maski, linker_label_list)

links_to_boundary(masks, links)

Deprecated.

loss(self, lbl, y)

Loss function for Omnipose. :param lbl: transformed labels in array [nimg x nchan x xy[0] x xy[1]] lbl[:,0] cell masks lbl[:,1] thresholded mask layer lbl[:,2] boundary field lbl[:,3] smooth distance field lbl[:,4] boundary-emphasizing weights lbl[:,5:] flow components :type lbl: ND-array, float :param y: network predictions, with dimension D, these are: y[:,:D] flow field components at 0,1,...,D-1 y[:,D] distance fields at D y[:,D+1] boundary fields at D+1 :type y: ND-tensor, float.

masks_to_affinity(masks, coords, steps, ...)

Convert label matrix to affinity graph.

masks_to_flows(masks[, affinity_graph, ...])

Convert masks to flows.

masks_to_flows_batch(batch[, links, device, ...])

Batch process flows.

masks_to_flows_torch(masks, affinity_graph)

Convert ND masks to flows.

mode_filter(masks)

super fast mode filter (compared to scipy, idk about PIL) to clean up interpolated labels

pill_decomposition(A, D)

random_crop_warp(img, Y, tyx, v1, v2, nchan, ...)

This sub-fuction of random_rotate_and_resize() recursively performs random cropping until a minimum number of cell pixels are found, then proceeds with augemntations.

random_rotate_and_resize(X[, Y, ...])

augmentation by random rotation and resizing

remove_bad_flow_masks(masks, flows[, ...])

remove masks which have inconsistent flows

scale_to_tenths(x)

sigmoid(x)

The sigmoid function.

spatial_affinity(affinity_graph, coords, shape)

Convert affinity graph in (S,N) format to (S,*DIMS) format.

split_spacetime(augmented_affinity, mask[, ...])

Split lineage labels into frame-by-frame labels and Cell ID / spacetime labeling.

step_factor(t)

Euler integration suppression factor.

steps_batch(p, dP, niter[, omni, suppress, ...])

Euler integration of pixel locations p subject to flow dP for niter steps in N dimensions.

torch_and(tensors)

Dispatch to torch_and_cpu or torch_and_gpu depending on the device of the first tensor in tensors.

torch_and_cpu(tensors)

Pair-wise logical AND using functools.reduce.

torch_and_gpu(tensors)

Vectorized logical AND via torch.all after stacking.

omnipose.utils

add_poisson_noise(image)

auto_chunked_quantile(tensor, q)

average_tiles_ND(y, subs, shape)

average results of network over tiles

bin_counts(data[, num_bins])

Compute the counts of values in bins.

border_indices(tyx)

Return flat indices of border values in ND.

clean_boundary(labels[, boundary_thickness, ...])

Delete boundary masks below a given size threshold within a certain distance from the boundary.

compute_density(x, y[, bw_method])

Compute the density of points along a curve.

compute_quantiles(sorted_array[, lower, upper])

Compute a pair of quantiles of a sorted array.

correct_illumination(img[, sigma])

cubestats(n)

Gets the number of m-dimensional hypercubes connected to the n-cube, including itself.

curve_filter(im[, filterWidth])

curveFilter : calculates the curvatures of an image.

extract_skeleton(distance_field)

find_boundaries(labels[, connectivity, ...])

Compute boundaries of labeled instances in an N-dimensional array.

find_files(directory, suffix[, exclude_suffixes])

Find files in a directory matching a suffix, excluding specific suffixes.

find_nonzero_runs(a)

findbetween(s[, string1, string2])

Find text between string1 and string2.

gamma_normalize(im, mask[, target, scale, ...])

generate_slices(image_shape, crop_size)

Generate slices for cropping an image into crops of size crop_size.

get_edge_masks(labels, dists)

Finds and returns masks that are largely cut off by the edge of the image.

get_flip(idx)

get_module(x)

get_neigh_inds(neighbors, coords, shape[, ...])

For L pixels and S steps, find the neighboring pixel indexes 0,1,...,L for each step.

get_neighbors(coords, steps, dim, shape[, ...])

Get the neighbor coordinates for each pixel in coords for each offset in steps.

get_neighbors_torch(input, steps)

This version not yet used/tested.

get_spruepoints(bw)

get_steps(dim)

Get a symmetrical list of all 3**N points in a hypercube represented by a list of all possible sequences of -1, 0, and 1 in ND.

get_supporting_inds(steps)

For each step 'v', find all pairs (i, j) such that steps[i] + steps[j] == steps[v], excluding the center index.

getname(path[, prefix, suffix, padding])

Extract the file name.

hysteresis_threshold(image, low, high)

Pytorch implementation of skimage.filters.apply_hysteresis_threshold().

is_integer(var)

kernel_setup(dim)

Get relevant kernel information for the hypercube of interest.

load_nested_list(file_path)

Helper function to load affinity graphs.

localnormalize(im[, sigma1, sigma2])

localnormalize_GPU(im[, sigma1, sigma2])

make_tiles_ND(imgi[, bsize, augment, ...])

make tiles of image to run at test-time

mask_outline_overlay(img, masks, outlines[, ...])

Apply a color overlay to a grayscale image based on a label matrix.

mono_mask_bd(masks, outlines[, color, a])

moving_average(x, w)

normalize99(Y[, lower, upper, ...])

normalize array/tensor so 0.0 is 0.01st percentile and 1.0 is 99.99th percentile Upper and lower percentile ranges configurable.

normalize99_hist(Y[, lower, upper, ...])

normalize array/tensor using 1% and 99% quantiles

normalize_field(mu[, use_torch, cutoff])

normalize all nonzero field vectors to magnitude 1

normalize_image(im, mask[, target, ...])

Normalize image by rescaling from 0 to 1 and then adjusting gamma to bring average background to specified value (0.5 by default).

pnormalize(Y[, p_min, p_max])

normalize array/tensor using p-norm

precompute_valid_mask(shape, steps[, device])

Boolean mask telling whether both a pixel and its neighbour at offset steps[k] are inside an N-D volume.

qnorm(Y[, nbins, bw_method, density_cutoff, ...])

quantile_rescale(Y[, lower, upper, ...])

ravel_index(b, shp)

rescale(T[, floor, ceiling, exclude_dims])

rotate(V, theta[, order, output_shape, center])

safe_divide(num, den[, cutoff])

Division ignoring zeros and NaNs in the denominator.

save_nested_list(file_path, nested_list)

Helper function to save affinity graphs.

searchsorted(tensor, value)

Find the indices where value should be inserted in tensor to maintain order.

skeletonize(labels[, method])

steps_to_indices(steps)

Get indices of the hupercubes sharing m-faces on the central n-cube.

subsample_affinity(augmented_affinity, slc, mask)

Helper function to subsample an affinity graph according to an image crop slice and a foreground selection mask.

thin_skeleton(image)

to_16_bit(im)

Rescale image [0,2^16-1] and then cast to uint16.

to_8_bit(im)

Rescale image [0,2^8-1] and then cast to uint8.

torch_norm(a[, dim, keepdim])

Wrapper for torch.linalg.norm to handle ARM architecture.

unaugment_tiles_ND(y, inds[, unet])

reverse test-time augmentations for averaging

unravel_index(index, shape)

omnipose.plot

apply_ncolor(masks[, offset, cmap, ...])

color_from_RGB(im, rgb, m[, bd, mode, ...])

color_grid(colors, **kwargs)

color_swatches(colors[, figsize, dpi, ...])

colored_line(x, y, ax[, z, line_width, MAP])

colored_line_segments(xs, ys[, zs, color, ...])

colorize(im[, colors, color_weights, ...])

colorize_GPU(im[, colors, color_weights, ...])

colorize_dask(im_dask[, colors, ...])

colorize_dask_fast(im_dask[, colors, ...])

colorize_dask_matmul(im_dask[, colors, ...])

A faster version of colorize_dask that uses a single matrix multiply instead of explicit loops or opt_einsum for the core contraction step.

create_colormap(image, labels)

Create a colormap based on the average color of each label in the image.

custom_new_gc(self)

faded_segment_resample(xs, ys[, zs, color, ...])

figure([nrow, ncol, aspect])

get_aspect(ax)

image_grid(images[, column_titles, ...])

imshow(imgs[, figsize, ax, hold, titles, ...])

Display one or more images.

plot_edges(shape, affinity_graph, neighbors, ...)

Render an affinity graph as line segments laid over an optional image.

rgb_flow(dP[, transparency, mask, norm, device])

Meant for stacks of dP, unsqueeze if using on a single plane.

segmented_resample(xs, ys[, zs, color, ...])

set_outline(ax[, outline_color, outline_width])

setup()

split_list(lst, N)

truncate_colormap(cmap[, minval, maxval, n])

vector_contours(fig, ax, mask[, crop, ...])