Fix label2rgb bug

This commit is contained in:
Johannes Schönberger
2013-11-09 22:04:28 +01:00
parent 615866ae16
commit 7f27d5bffb
2 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -112,7 +112,7 @@ def label2rgb(label, image=None, colors=None, alpha=0.3,
label = label - offset # Make sure you don't modify the input array.
bg_label -= offset
new_type = np.min_scalar_type(label.max())
new_type = np.min_scalar_type(int(label.max()))
if new_type == np.bool:
new_type = np.uint8
label = label.astype(new_type)
+3 -2
View File
@@ -114,11 +114,12 @@ def relabel_sequential(label_field, offset=1):
>>> relab
array([5, 5, 6, 6, 7, 9, 8])
"""
m = label_field.max()
if not np.issubdtype(label_field.dtype, np.int):
label_field = label_field.astype(np.int)
new_type = np.min_scalar_type(int(m))
label_field = label_field.astype(new_type)
labels = np.unique(label_field)
labels0 = labels[labels != 0]
m = labels.max()
if m == len(labels0): # nothing to do, already 1...n labels
return label_field, labels, labels
forward_map = np.zeros(m+1, int)