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

1

S. Weinert et al “Detection and Segmentation of Cell Nuclei in Virtual Microscopy Images: A Minimum-Model Approach” in Nature Scientific Reports,vol.2,no.503, doi:10.1038/srep00503, 2012.

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 (array_like) – A label image where all values in ‘indices’ are set to zero.

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

2

J. Seo et al “Fast Contour-Tracing Algorithm Based on a Pixel- Following Method for Image Sensors” in Sensors,vol.16,no.353, doi:10.3390/s16030353, 2016.

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