histomicstk.segmentation.label

This package contains functions for post-processing labeled segmentation masks produced by segmentation algorithms.

histomicstk.segmentation.label.area_open(im_label, min_area)[source]

Removes small objects from label image.

Parameters:
  • im_label (array_like) – A uint32 type label image generated by segmentation methods.

  • min_area (int) – minimum area threshold for objects. Objects with fewer than ‘min_area’ pixels will be zeroed to merge with background.

Returns:

im_open – A uint32 label where objects with pixels < min_area are removed.

Return type:

array_like

Notes

Objects are assumed to have positive nonzero values. im_label image will be condensed during processing.

histomicstk.segmentation.label.compact(im_label, compaction=3)[source]

Performs a thinning operation on a label image to remove thin protrusions from objects that are in contact with the background. Applies a distance transform and sequentially removes pixels with small distances to background that are not connected to higher distance pixels.

Parameters:
  • im_label (array_like) – A labeled segmentation mask

  • compaction (int) – Factor used in compacting objects to remove thin protrusions. Referred to as d in the reference below. Default value = 3.

Notes

Implemented from the reference below.

Returns:

im_compact – A labeled segmentation mask with thin protrusions removed.

Return type:

array_like

References

histomicstk.segmentation.label.condense(im_label)[source]

Shifts labels in a label image to fill in gaps corresponding to missing values.

Parameters:

im_label (array_like) – A label image generated by segmentation methods.

Returns:

Condensed – A label image where all values > 0 are shifted down to fill gaps.

Return type:

array_like

histomicstk.segmentation.label.delete(im_label, indices)[source]

Deletes objects with values in ‘indices’ from label image, writing them over with zeros to assimilate with background.

Parameters:
  • im_label (array_like) – A label image generated by segmentation methods.

  • indices (array_like) – An n-length array of strictly positive integer values to delete from ‘im_label’.

Returns:

Deleted – A label image where all values in ‘indices’ are set to zero.

Return type:

array_like

Notes

A call to CondenseLabel can squeeze label image values to fill in gaps from deleted values.

histomicstk.segmentation.label.delete_border(im_label)[source]

Deletes objects touching the border of the image and relabel

Parameters:

im_label (array_like) – A label mask generated by segmentation methods.

Returns:

im_label_del – A label mask where in all the objects touching the image border have been deleted

Return type:

array_like

histomicstk.segmentation.label.delete_overlap(im_label, overlap_info)[source]

Deletes overlapping regions from an image label based on overlap information and tile size.

Args:

im_label (ndarray): Image label represented as a NumPy array. overlap_info (dict): Dictionary containing overlap information.

It should have the following keys: ‘left’, ‘right’, ‘top’, and ‘bottom’, each specifying the overlap amount in pixels.

Returns:

ndarray: Image label with overlapping regions deleted.

Note:

This function assumes the necessary imports, such as np, are already present.

histomicstk.segmentation.label.dilate_xor(im_label, neigh_width=8)[source]

Computes a label mask highlighting a ring-like neighborhood of each object or region in a given label mask

Parameters:
  • im_label (array_like) – A labeled mask image wherein intensity of a pixel is the ID of the object it belongs to. Non-zero values are considered to be foreground objects.

  • neigh_width (float, optional) – The width of the ring-like neighborhood around each object.

Returns:

im_neigh_label – A labeled mask image highlighting pixels in a ring-like neighborhood of width upto neigh_width around each object in the given label mask. The intensity of each pixel in the ring-like neighborhood is set equal to the label of the closest object in the given label mask. other pixels (including the ones inside objects) are set to zero.

Return type:

array_like

histomicstk.segmentation.label.perimeter(im_label, conn=4)[source]

Converts a label or binary mask image to a binary perimeter image.

Uses 4-neighbor or 8-neighbor shifts to detect pixels whose values do not agree with their neighbors.

Parameters:
  • im_label (array_like) – A label or binary mask image.

  • conn (double or int) – Neighborhood connectivity to evaluate. Valid values are 4 or 8. Default value = 4.

Returns:

Mask – A binary image where object perimeter pixels have value 1, and non-perimeter pixels have value 0.

Return type:

array_like

histomicstk.segmentation.label.remove_overlap_nuclei(nuclei_list, nuclei_format, return_selected_nuclei=False)[source]

Remove overlapping nuclei using spatial indexing and parallel processing.

This function removes overlapping nuclei polygons from input using an STRtree index.

Args:

nuclei_list (list): List of dictionaries with ‘points’ for polygons. nuclei_format (str, optional): Output format (‘polygon’ or ‘bbox’). return_selected (bool, optional): Return indices of selected nuclei (default: False).

Returns:

output_list (list): New list with overlapping nuclei removed. selected_nuclei (list, optional): Indices of selected nuclei.

histomicstk.segmentation.label.shuffle(im_label)[source]

Shuffles labels in a label image to improve visualization and enhance object boundaries.

Parameters:

im_label (array_like) – A label image generated by segmentation methods.

Returns:

Shuffled – A label image where all values > 0 are randomly shuffled.

Return type:

array_like

See also

histomicstk.segmentation.label.CondenseLabel

histomicstk.segmentation.label.split(im_label, conn=8)[source]

Re-labels objects that have multiple non-contiguous portions to create a new label image where each object is contiguous.

Parameters:
  • im_label (array_like) – A uint32 type label image generated by segmentation methods.

  • conn (int) – Neighborhood connectivity to define contiguity. Valid values are 4 or 8. Default value = 4.

Notes

Objects are assumed to have positive nonzero values.

Returns:

Split – A uint32 label where discontiguous objects are split and relabeled.

Return type:

array_like

histomicstk.segmentation.label.trace_object_boundaries(im_label, conn=4, trace_all=False, x_start=None, y_start=None, max_length=None, simplify_colinear_spurs=True, eps_colinear_area=0.01, region_props=None)[source]

Performs exterior boundary tracing of one or more objects in a label mask. If a starting point is not provided then a raster scan will be performed to identify the starting pixel.

Parameters:
  • im_label (array_like) – A binary mask image.

  • conn (int) – Neighborhood connectivity to evaluate. Valid values are 4 or 8. Default value = 4.

  • trace_all (bool) – Specify True if you want to trace boundaries of all objects. Default = False

  • x_start (int) – Starting horizontal coordinate to begin tracing. Default value = None.

  • y_start (int) – Starting vertical coordinate to begin tracing. Default value = None.

  • max_length (int) – Maximum boundary length to trace before terminating. Default value = None.

  • simplify_colinear_spurs (bool) – If True colinear streaks/spurs in the object boundary will be simplified/removed. Note that if the object boundary is entirely colinear then the object itself will be removed. Default = True

  • eps_colinear_area (int) – Minimum area of triangle formed by three consecutive points on the contour for them to be considered as non-colinear. Default value = 0.01.

Notes

The Improved Simple Boundary Follower (ISBF) from the reference below is used for 4-connected tracing. This algorithm provides accurate tracing with competitive execution times. 8-connected tracing is implemented using the Moore tracing algorithm.

Returns:

  • X (array_like) – A set of 1D array of horizontal coordinates of contour seed pixels for tracing.

  • Y (array_like) – A set of 1D array of the vertical coordinates of seed pixels for tracing.

References

histomicstk.segmentation.label.width_open(im_label, width)[source]

Removes thin objects from label image using maximum of distance transform values within each object.

Parameters:
  • im_label (array_like) – A uint32 type label image generated by segmentation methods.

  • width (int) – width threshold for objects. Objects with fewer than ‘Area’ pixels will be zeroed to merge with background.

Notes

Objects are assumed to have positive nonzero values. A binary mask is generated for each object setting all other objects to the background value (0). The maximum chamfered distance transform value of this mask is used to represent the object width.

Returns:

im_thinned – A uint32 label where objects with pixels < Area are removed.

Return type:

array_like