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
ctolof an entry inmapis assigned that entry’s label; connected components are then relabelled withskimage.measure.label().- Parameters:
- img
numpy.ndarrayordarsia.Image Input image in RGB colour space.
- map
dict,optional Maps colour names to
(label, rgb)pairs, wherelabelis an int andrgba tuple of floats in[0, 1]. Defaults to a predefined map for white/black/red/green/blue/cyan/magenta/yellow (labels 0-7).- ctol
float,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.
- significance
float,optional Minimum significance of a label for it to be kept.
- img
- Returns:
numpy.ndarrayordarsia.ImageLabelled regions, in the same format as
img.