Postprocessing

Functions used to clean and refine segmentation results.

Label and clean instances

Label disconnected instances:

Clean segmentation results:

See an example of application here.

bigfish.segmentation.label_instances(image_binary)

Count and label the different instances previously segmented in an image.

Parameters:
image_binarynp.ndarray, bool

Binary segmented image with shape (z, y, x) or (y, x).

Returns:
image_labelnp.ndarray, np.int64

Labelled image. Each instance is characterized by the same pixel value.

bigfish.segmentation.merge_labels(image_label_1, image_label_2)

Combine two partial labels of the same image.

To prevent merging conflict, labels should not be rescale.

Parameters:
image_label_1np.ndarray, np.int64

Labelled image with shape (z, y, x) or (y, x).

image_label_2np.ndarray, np.int64

Labelled image with shape (z, y, x) or (y, x).

Returns:
image_labelnp.ndarray, np.int64

Labelled image with shape (z, y, x) or (y, x).

bigfish.segmentation.clean_segmentation(image, small_object_size=None, fill_holes=False, smoothness=None, delimit_instance=False)

Clean segmentation results (binary masks or integer labels).

Parameters:
imagenp.ndarray, np.int64 or bool

Labelled or masked image with shape (y, x).

small_object_sizeint or None

Areas with a smaller surface (in pixels) are removed.

fill_holesbool

Fill holes within a labelled or masked area.

smoothnessint or None

Radius of a median kernel filter. The higher the smoother instance boundaries are.

delimit_instancebool

Delimit clearly instances boundaries by preventing contact between each others.

Returns:
image_cleanednp.ndarray, np.int64 or bool

Cleaned image with shape (y, x).

bigfish.segmentation.remove_disjoint(image)

For each instances with disconnected parts, keep the larger one.

Parameters:
imagenp.ndarray, np.int, np.uint or bool

Labelled image with shape (z, y, x) or (y, x).

Returns:
image_cleanednp.ndarray, np.int or np.uint

Cleaned image with shape (z, y, x) or (y, x).


Compute instance statistics

Compute statistics for each segmented instance:

bigfish.segmentation.compute_mean_diameter(image_label)

Compute the averaged size of the segmented instances.

For each instance, we compute the diameter of an object with an equivalent surface. Then, we average the diameters.

Parameters:
image_labelnp.ndarray, np.int or np.uint

Labelled image with shape (y, x).

Returns:
mean_diameterfloat

Averaged size of the segmented instances.

bigfish.segmentation.compute_mean_convexity_ratio(image_label)

Compute the averaged convexity ratio of the segmented instances.

For each instance, we compute the ratio between its area and the area of its convex hull. Then, we average the diameters.

Parameters:
image_labelnp.ndarray, np.int or np.uint

Labelled image with shape (y, x).

Returns:
mean_convexity_ratiofloat

Averaged convexity ratio of the segmented instances.

bigfish.segmentation.compute_surface_ratio(image_label)

Compute the averaged surface ratio of the segmented instances.

We compute the proportion of surface occupied by instances.

Parameters:
image_labelnp.ndarray, np.int or np.uint

Labelled image with shape (y, x).

Returns:
surface_ratiofloat

Surface ratio of the segmented instances.

bigfish.segmentation.count_instances(image_label)

Count the number of instances annotated in the image.

Parameters:
image_labelnp.ndarray, np.int or np.uint

Labelled image with shape (y, x).

Returns:
nb_instancesint

Number of instances in the image.


Match cells and nuclei

Match nuclei and cells:

bigfish.multistack.match_nuc_cell(nuc_label, cell_label, single_nuc, cell_alone)

Match each nucleus instance with the most overlapping cell instance.

Parameters:
nuc_labelnp.ndarray, np.int or np.uint

Labelled image of nuclei with shape (z, y, x) or (y, x).

cell_labelnp.ndarray, np.int or np.uint

Labelled image of cells with shape (z, y, x) or (y, x).

single_nucbool

Authorized only one nucleus in a cell.

cell_alonebool

Authorized cell without nucleus.

Returns:
new_nuc_labelnp.ndarray, np.int or np.uint

Labelled image of nuclei with shape (z, y, x) or (y, x).

new_cell_labelnp.ndarray, np.int or np.uint

Labelled image of cells with shape (z, y, x) or (y, x).