omnipose.core#

affinity_to_boundary(masks, affinity_graph, ...)

Convert affinity graph to boundary map.

affinity_to_edges(affinity_graph, ...)

Convert symmetric affinity graph to list of edge tuples for connected components labeling.

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

Convert affinity graph to label matrix using connected components.

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])

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)

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, ...)

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_neigh_inds(coords, shape, steps)

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

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.

links_to_mask(masks, links)

Convert linked masks to stitched masks.

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

most_frequent(neighbor_masks)

parametrize(steps, labs, unique_L, inds, ...)

Parametrize 2D boundaries.

parametrize_contours(steps, labs, unique_L, ...)

Helper function to sort 2D contours into cyclic paths.

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

sigmoid(x)

The sigmoid function.

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.

omnipose.utils#

add_gaussian_noise(image[, mean, var])

add_poisson_noise(image)

apply_gaussian_blur(image, kernel_size, sigma)

Applies a Gaussian blur to the image.

apply_shifts(moving_images, shifts)

auto_chunked_quantile(tensor, q)

average_tiles_ND(y, subs, shape)

average results of network over tiles

bbox_to_slice(bbox, shape[, pad, im_pad])

return the tuple of slices for cropping an image based on the skimage.measure bounding box optional padding allows for the bounding box to be expanded, but not outside the original image dimensions

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_final_shifts(pairwise_shifts)

correct_illumination(img[, sigma])

crop_bbox(mask[, pad, iterations, im_pad, ...])

Take a label matrix and return a list of bounding boxes identifying clusters of labels.

cross_reg(imstack[, upsample_factor, order, ...])

Find the transformation matrices for all images in a time series to align to the beginning frame.

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_files(directory, suffix[, exclude_suffixes])

find_nonzero_runs(a)

findbetween(s[, string1, string2])

Find text between string1 and string2.

gaussian_kernel(size, sigma)

Creates a 2D Gaussian kernel with mean 0.

generate_slices(image_shape, crop_size)

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

get_boundary(mask)

ND binary mask boundary using mahotas.

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 coordinates of all neighbor pixels.

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.

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

make_unique(masks)

Relabel stack of label matrices such that there is no repeated label across slices.

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.

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).

normalize_stack(vol, mask[, bg, ...])

Adjust image stacks so that background is (1) consistent in brightness and (2) brought to an even average via semantic gamma normalization.

pairwise_registration(image_stack[, ...])

phase_cross_correlation_GPU(image_stack[, ...])

phase_cross_correlation_GPU_old(image_stack)

ravel_index(b, shp)

remap_pairs(pairs, replacements)

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

Rescale data between 0 and 1

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.

shift_stack(imstack, shifts[, order, cval])

Shift each time slice of imstack according to list of 2D shifts.

shifts_to_slice(shifts, shape)

Find the minimal crop box from time lapse registraton shifts.

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])

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, ...])

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

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

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

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, ...])

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

Display a grid of images with uniform spacing.

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

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

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, ...])

sinebow(N[, bg_color, offset])

Generate a color dictionary for use in visualizing N-colored labels.