darsia.label_image#

label_image(img, map=None, ctol=0.01, ensure_connectivity=True, expand_labels=True, significance=None)[source]#

Segment an image by matching pixel colours to a reference map.

Each pixel whose RGB value is within ctol of an entry in map is assigned that entry’s label; connected components are then relabelled with skimage.measure.label().

Parameters:
imgnumpy.ndarray or darsia.Image

Input image in RGB colour space.

mapdict, optional

Maps colour names to (label, rgb) pairs, where label is an int and rgb a tuple of floats in [0, 1]. Defaults to a predefined map for white/black/red/green/blue/cyan/magenta/yellow (labels 0-7).

ctolfloat, optional

Tolerance for colour matching. Default 0.01.

ensure_connectivitybool, optional

Ensure labels are connected regions. Default True.

expand_labelsbool, optional

Expand labels to fill unlabelled pixels. Default True.

significancefloat, optional

Minimum significance of a label for it to be kept.

Returns:
numpy.ndarray or darsia.Image

Labelled regions, in the same format as img.