bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / segmentation / _join / relabel_sequential
function
skimage.segmentation._join:relabel_sequential
source: /dev/scikit-image/src/skimage/segmentation/_join.py :76
Signature
def relabel_sequential ( label_field , offset = 1 ) Summary
Relabel arbitrary labels to {offset, ... offset + number_of_labels}.
Extended Summary
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).
Parameters
label_field: numpy array of int, arbitrary shapeAn array of labels, which must be non-negative integers.
offset: int, optionalThe return labels will start at
offset, which should be strictly positive.
Returns
relabeled: numpy array of int, same shape as `label_field`The input label field with labels mapped to {offset, ..., number_of_labels + offset - 1}. The data type will be the same as
label_field, except when offset + number_of_labels causes overflow of the current data type.forward_map: ArrayMapThe 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 relabeled.
inverse_map: ArrayMapThe 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
label_field.
Notes
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.
Examples
from skimage.segmentation import relabel_sequential label_field = np.array([1, 1, 5, 5, 8, 99, 42]) relab, fw, inv = relabel_sequential(label_field) relab print(fw) np.array(fw) np.array(inv)✓
(fw[label_field] == relab).all() (inv[relab] == label_field).all()✗
relab, fw, inv = relabel_sequential(label_field, offset=5) relab✓
Aliases
-
skimage.segmentation.relabel_sequential