relabel_sequential(label_field, offset=1)
This function also returns the forward map (mapping the original labels to the reduced labels) and the inverse map (mapping the reduced labels back to the original ones).
The label 0 is assumed to denote the background and is never remapped.
The forward map can be extremely big for some inputs, since its length is given by the maximum of the label field. However, in most situations, label_field.max()
is much smaller than label_field.size
, and in these cases the forward map is guaranteed to be smaller than either the input or output images.
An array of labels, which must be non-negative integers.
The return labels will start at :None:None:`offset`
, which should be strictly positive.
The input label field with labels mapped to {offset, ..., number_of_labels + offset - 1}. The data type will be the same as :None:None:`label_field`
, except when offset + number_of_labels causes overflow of the current data type.
The map from the original label space to the returned label space. Can be used to re-apply the same mapping. See examples for usage. The output data type will be the same as :None:None:`relabeled`
.
The map from the new label space to the original space. This can be used to reconstruct the original label field from the relabeled one. The output data type will be the same as :None:None:`label_field`
.
Relabel arbitrary labels to {:None:None:`offset`
, ... :None:None:`offset`
+ number_of_labels}.
>>> from skimage.segmentation import relabel_sequentialThis example is valid syntax, but we were not able to check execution
... label_field = np.array([1, 1, 5, 5, 8, 99, 42])
... relab, fw, inv = relabel_sequential(label_field)
... relab array([1, 1, 2, 2, 3, 5, 4])
>>> print(fw) ArrayMap: 1 → 1 5 → 2 8 → 3 42 → 4 99 → 5This example is valid syntax, but we were not able to check execution
>>> np.array(fw) array([0, 1, 0, 0, 0, 2, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5])This example is valid syntax, but we were not able to check execution
>>> np.array(inv) array([ 0, 1, 5, 8, 42, 99])This example is valid syntax, but we were not able to check execution
>>> (fw[label_field] == relab).all() TrueThis example is valid syntax, but we were not able to check execution
>>> (inv[relab] == label_field).all() TrueThis example is valid syntax, but we were not able to check execution
>>> relab, fw, inv = relabel_sequential(label_field, offset=5)See :
... relab array([5, 5, 6, 6, 7, 9, 8])
The following pages refer to to this document either explicitly or contain code examples using this.
skimage.segmentation._join.relabel_sequential
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them