用法:
skimage.segmentation.relabel_sequential(label_field, offset=1)
将任意标签重新标记为 {offset, ... offset + number_of_labels}。
此函数还返回正向映射(将原始标签映射到缩减标签)和反向映射(将缩减标签映射回原始标签)。
- label_field:int任意形状的numpy数组
标签数组,必须是非负整数。
- offset:int 可选
返回标签将从偏移量开始,这应该是严格的正数。
- relabeled:int 的 numpy 数组与label_field
标签映射到 {offset, ..., number_of_labels + offset - 1} 的输入标签字段。数据类型将与label_field 相同,除非偏移量+number_of_labels 导致当前数据类型溢出。
- forward_map:ArrayMap
从原始标签空间到返回标签空间的映射。可用于重新应用相同的映射。请参阅使用示例。输出数据类型将与重新标记的相同。
- inverse_map:ArrayMap
从新标签空间到原始空间的映射。这可用于从重新标记的标签字段中重建原始标签字段。输出数据类型将与label_field 相同。
参数:
返回:
注意:
假定标签 0 表示背景并且从不重新映射。
对于某些输入,前向映射可能非常大,因为它的长度由标签字段的最大值给出。然而,在大多数情况下,
label_field.max()
比label_field.size
小得多,在这些情况下,前向映射保证小于输入或输出图像。例子:
>>> 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 array([1, 1, 2, 2, 3, 5, 4]) >>> print(fw) ArrayMap: 1 → 1 5 → 2 8 → 3 42 → 4 99 → 5 >>> 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]) >>> np.array(inv) array([ 0, 1, 5, 8, 42, 99]) >>> (fw[label_field] == relab).all() True >>> (inv[relab] == label_field).all() True >>> relab, fw, inv = relabel_sequential(label_field, offset=5) >>> relab array([5, 5, 6, 6, 7, 9, 8])
相关用法
- Python skimage.segmentation.random_walker用法及代码示例
- Python skimage.segmentation.active_contour用法及代码示例
- Python skimage.segmentation.flood_fill用法及代码示例
- Python skimage.segmentation.clear_border用法及代码示例
- Python skimage.segmentation.felzenszwalb用法及代码示例
- Python skimage.segmentation.watershed用法及代码示例
- Python skimage.segmentation.expand_labels用法及代码示例
- Python skimage.segmentation.find_boundaries用法及代码示例
- Python skimage.segmentation.slic用法及代码示例
- Python skimage.segmentation.flood用法及代码示例
- Python skimage.segmentation.join_segmentations用法及代码示例
- Python skimage.feature.graycomatrix用法及代码示例
- Python skimage.color.lab2lch用法及代码示例
- Python skimage.draw.random_shapes用法及代码示例
- Python skimage.feature.blob_doh用法及代码示例
- Python skimage.feature.blob_dog用法及代码示例
- Python skimage.filters.unsharp_mask用法及代码示例
- Python skimage.registration.optical_flow_tvl1用法及代码示例
- Python skimage.filters.rank.noise_filter用法及代码示例
- Python skimage.exposure.histogram用法及代码示例
注:本文由纯净天空筛选整理自scikit-image.org大神的英文原创作品 skimage.segmentation.relabel_sequential。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。