From 069cba50efc99b5bb75ab7715b7522807174015b Mon Sep 17 00:00:00 2001 From: "Josh Warner (Mac)" Date: Wed, 7 May 2014 23:54:17 -0500 Subject: [PATCH] FIX: Address non-int DeprecationWarning from NumPy --- skimage/segmentation/_join.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/skimage/segmentation/_join.py b/skimage/segmentation/_join.py index 892b85e2..31dadf6e 100644 --- a/skimage/segmentation/_join.py +++ b/skimage/segmentation/_join.py @@ -71,7 +71,7 @@ def relabel_sequential(label_field, offset=1): ------- relabeled : numpy array of int, same shape as `label_field` The input label field with labels mapped to - {1, ..., number_of_labels}. + {offset, ..., number_of_labels}. forward_map : numpy array of int, shape ``(label_field.max() + 1,)`` The map from the original label space to the returned label space. Can be used to re-apply the same mapping. See examples @@ -113,16 +113,18 @@ def relabel_sequential(label_field, offset=1): >>> relab, fw, inv = relabel_sequential(label_field, offset=5) >>> relab array([5, 5, 6, 6, 7, 9, 8]) + """ m = label_field.max() if not np.issubdtype(label_field.dtype, np.int): new_type = np.min_scalar_type(int(m)) label_field = label_field.astype(new_type) + m = label_field.max() # Ensures m is an integer labels = np.unique(label_field) labels0 = labels[labels != 0] if m == len(labels0): # nothing to do, already 1...n labels return label_field, labels, labels - forward_map = np.zeros(m+1, int) + forward_map = np.zeros(m + 1, int) forward_map[labels0] = np.arange(offset, offset + len(labels0) + 1) if not (labels == 0).any(): labels = np.concatenate(([0], labels))