shape_detection#

Module with routines for shape and size detection of objects such as cells.

Note

The shape detection is based on a seeded and masked watershed. The module is based on the ndimage library. For faster implementation of intensity and radial measurements see the modules listed below.

detect_shape(source, seeds, threshold=None, verbose=False, processes=None, as_binary_mask=False, return_sizes=False, seeds_as_labels=False, watershed_line=True)[source]#

Detect object shapes by generating a labeled image from seeds.

Optionally, the output is replaced by to a mere binary mask and the distinct shapes sizes are also returned.

Parameters:
  • source (array, str or Source) – Source image.

  • seeds (array, str or Source) – Cell centers as point coordinates if seeds_as_labels is False. See below otherwise.

  • threshold (float or None) – Threshold to determine mask for watershed, pixel below this are treated as background. If None, the seeds are expanded indefinitely.

  • verbose (bool) – If True, print progress info.

  • as_binary_mask (bool, optional) – If the first output is to be the mask of all shapes, by default False.

  • return_sizes (bool, optional) – If the sizes of the various shapes are to be returned too, by default False.

  • seeds_as_labels (bool, optional) – Defaults to False. If True the input seeds is considered to be a labeled image w/ the initial basins.

  • watershed_line (bool, optional) – Defaults to True. If True the watershedding is made with a line of background pixels inbetween the labeled regions. The value True is forced if as_binary_mask is True.

Returns

shapesarray

Labeled image, where each label indicates an object. Optionally replaced by shapes>0, see above.

sizes : (optional) the sizes of the shapes, in the same order are the seeds.

find_intensity(source, label, max_label=None, method='sum', verbose=False)[source]#

Find integrated intensity given object shapes as labeled image.

Arguments

sourcearray, str, or Source

Source to measure intensities from.

labelarray, str, or Source

Labeled image with a separate label for each object.

max_labelint or None

Maximal label to include. If None, use all.

method{‘sum’, ‘mean’, ‘max’, ‘min’}

Method to use to measure the intensities in each object’s area.

verbosebool

If True, print progress information.

Returns

intensitiesarray

Measured intensities.

find_size(label, max_label=None, verbose=False)[source]#

Find size given object shapes as a labled image

Arguments

labelarray, str or Source

Labeled image in which each object has its own label.

max_labelint or None

Maximal label to include, if None use all label.

verbosebool

Print progress info.

Returns

sizesarray

Measured intensities

labeled_pixels_from_centers(centers, weights, shape)[source]#

label the pixels specify by the centers with the weights.

Parameters:
  • centers (np.ndarray) – (n_points,dim) array with points coords, its dtype is the one of weights

  • weights (np.ndarray) – (n_points,) shaped array

  • shape (tuple) – the shape of the output array.