baby.brain.BabyBrain

class baby.brain.BabyBrain(morph_model_file=None, flattener_file=None, celltrack_model_file=None, budassign_model_file=None, pixel_size=0.263, default_image_size=None, params={'connectivity': (2, 2, 1), 'edge_sub_dilations': 1, 'fit_radial': True, 'group_thresh_expansion': 0.1, 'interior_threshold': (0.7, 0.5, 0.5), 'nclosing': (1, 0, 0), 'nopening': (1, 0, 0), 'pedge_thresh': 0.001, 'use_group_thresh': True}, clogging_thresh=1, min_bud_tps=3, isbud_thresh=0.5, session=None, graph=None, print_info=False, suppress_errors=False, error_dump_dir=None)

Bases: object

Coordinator for the segmentation and tracking models

Models are specified by file name, which can either be the path to a model file or the name of the file in the default “models” dir shipped with this package. If any are left unspecified, then default models will be loaded.

Parameters
  • morph_model_file – neural network model taking a stack of images and outputting predictions according to the paired flattener model.

  • flattener_file – a saved SegmentationFlattening model specifying the trained target types for each output layer of the neural network.

  • celltrack_model_file

  • budassign_model_file

  • default_image_size

  • params – dict of keyword parameters to be passed to the morph_seg_grouped function when segmenting.

  • session – optionally specify the Tensorflow session to load the neural network model into (useful only for Tensorflow versions <2)

  • graph – optionally specify the Tensorflow graph to load the neural network model into (useful only for Tensorflow versions <2)

  • suppress_errors – whether or not to catch Exceptions raised during segmentation or tracking. If True, then any Exceptions will be logged using standard Python logging.

  • error_dump_dir – optionally specify a directory in which to dump input parameters when an error is caught.

Attributes
depth

Methods

segment(bf_img_batch[, yield_edgemasks, ...])

Generator yielding segmented output for a batch of input images

segment_and_track(bf_img_batch[, ...])

Generator yielding segmented and tracked output for a batch of input images

segment_and_track_parallel(bf_img_batch[, ...])

Segment and track a batch of input images using joblib

morph_predict

__init__(morph_model_file=None, flattener_file=None, celltrack_model_file=None, budassign_model_file=None, pixel_size=0.263, default_image_size=None, params={'connectivity': (2, 2, 1), 'edge_sub_dilations': 1, 'fit_radial': True, 'group_thresh_expansion': 0.1, 'interior_threshold': (0.7, 0.5, 0.5), 'nclosing': (1, 0, 0), 'nopening': (1, 0, 0), 'pedge_thresh': 0.001, 'use_group_thresh': True}, clogging_thresh=1, min_bud_tps=3, isbud_thresh=0.5, session=None, graph=None, print_info=False, suppress_errors=False, error_dump_dir=None)

Methods

__init__([morph_model_file, flattener_file, ...])

morph_predict(X[, needs_context])

segment(bf_img_batch[, yield_edgemasks, ...])

Generator yielding segmented output for a batch of input images

segment_and_track(bf_img_batch[, ...])

Generator yielding segmented and tracked output for a batch of input images

segment_and_track_parallel(bf_img_batch[, ...])

Segment and track a batch of input images using joblib

Attributes

depth

segment(bf_img_batch, yield_edgemasks=False, yield_masks=False, yield_preds=False, yield_volumes=False, refine_outlines=False)

Generator yielding segmented output for a batch of input images

Parameters
  • bf_img_batch – a list of ndarray with shape (X, Y, Z), or equivalently an ndarray with shape (N_images, X, Y, Z)

  • yield_masks – if set to True, additionally yield filled cell masks in each output dict

  • yield_edgemasks – if set to True, additionally yield edge masks in each output dict

  • yield_preds – if set to True, additionally yield full prediction output from neural network

Yields

for each image in bf_img_batch a dict with - centres: list of float pairs corresponding to (x, y) coords for

each detected cell,

  • angles: list of lists of floats corresponding, for each cell, to angles (radians) used to form active contour outline in radial space

  • radii: list of lists of floats corresponding, for each cell, to radii used to form active contour outline in radial space

  • edgemasks: (optional) an ndarray of dtype “bool” with shape (N_cells, X, Y) specifying the rasterised edge for each segmented cell

  • volumes: (optional) list of floats corresponding, for each cell, to the conical section method for cell volume estimation

segment_and_track(bf_img_batch, tracker_states=None, yield_next=False, yield_edgemasks=False, assign_mothers=False, return_baprobs=False, refine_outlines=False, yield_volumes=False)

Generator yielding segmented and tracked output for a batch of input images

Parameters
  • bf_img_batch – a list of ndarray with shape (X, Y, Z), or equivalently an ndarray with shape (N_images, X, Y, Z)

  • tracker_states – a generator of tracker states from the previous time point as yielded by this function when yield_next is True

  • yield_next – whether to yield updated tracking states for subsequent calls to this function

  • yield_edgemasks – whether to include edge masks in the output

  • assign_mothers – whether to include mother assignments in the output

  • return_baprobs – whether to include the bud assignment probability matrix in the output

  • yield_volumes – whether to calculate and include volume estimates in the output

Yields

for each image in bf_img_batch a dict with - centres: list of float pairs corresponding to (x, y) coords for

each detected cell,

  • angles: list of lists of floats corresponding, for each cell, to angles (radians) used to form active contour outline in radial space

  • radii: list of lists of floats corresponding, for each cell, to radii used to form active contour outline in radial space

  • cell_label: list of int corresponding to tracked global ID for each cell detected in this image (indexed from 1)

  • mother_assign: (optional) list of int specifying for each (global) cell label ID, the cell label ID of the corresponding mother (0 if no mother was found)

  • p_bud_assign: (optional) matrix as a list of lists of floats, specifying the probability that a cell (outer list) is a mother to another cell (inner lists) in this image

  • edgemasks: (optional) an ndarray of dtype “bool” with shape (N_cells, X, Y) specifying the rasterised edge for each segmented cell

If yield_next is True, yields the dict described above and tracker states for this time point as a tuple

segment_and_track_parallel(bf_img_batch, tracker_states=None, yield_next=False, yield_edgemasks=False, assign_mothers=False, return_baprobs=False, refine_outlines=False, yield_volumes=False, njobs=-2)

Segment and track a batch of input images using joblib

Parameters
  • bf_img_batch – a list of ndarray with shape (X, Y, Z), or equivalently an ndarray with shape (N_images, X, Y, Z)

  • tracker_states – a generator of tracker states from the previous time point as yielded by this function when yield_next is True

  • yield_next – whether to yield updated tracking states for subsequent calls to this function

  • yield_edgemasks – whether to include edge masks in the output

  • assign_mothers – whether to include mother assignments in the output

  • return_baprobs – whether to include the bud assignment probability matrix in the output

  • yield_volumes – whether to calculate and include volume estimates in the output

Returns

a list containing for each image in bf_img_batch a dict with - centres: list of float pairs corresponding to (x, y) coords for

each detected cell,

  • angles: list of lists of floats corresponding, for each cell, to angles (radians) used to form active contour outline in radial space

  • radii: list of lists of floats corresponding, for each cell, to radii used to form active contour outline in radial space

  • cell_label: list of int corresponding to tracked global ID for each cell detected in this image (indexed from 1)

  • mother_assign: (optional) list of int specifying for each (global) cell label ID, the cell label ID of the corresponding mother (0 if no mother was found)

  • p_bud_assign: (optional) matrix as a list of lists of floats, specifying the probability that a cell (outer list) is a mother to another cell (inner lists) in this image

  • edgemasks: (optional) an ndarray of dtype “bool” with shape (N_cells, X, Y) specifying the rasterised edge for each segmented cell

If yield_next is True, returns the dict described above and tracker states for this time point as a tuple