Skip to content

Commit 962ab95

Browse files
authored
Merge pull request #1236 from frheault/hot_fix_numerical_imprecision
Avoid numerical shenanigans
2 parents 7f40ee8 + 2951342 commit 962ab95

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

scilpy/tractanalysis/distance_to_centroid.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@ def closest_match_to_centroid(bundle_pts, centroid_pts, nb_pts):
4747
"""
4848
# A kdtree is used to find the nearest euclidian neighbors between
4949
# all voxels (bundle) and the streamline (centroid)
50+
if len(centroid_pts) != nb_pts:
51+
raise ValueError('The number of points in the centroid_pts must be '
52+
'equal to nb_pts')
5053
tree = KDTree(centroid_pts, copy_data=True)
5154
_, labels = tree.query(bundle_pts, k=1)
55+
labels += 1
5256

53-
# No matter how many points are in the centroids, labels will be between
54-
# 1 and nb_pts
55-
labels = (labels / np.max(labels) * (nb_pts - 1)) + 1
56-
57-
return labels.astype(np.uint16)
58-
57+
return labels
5958

6059
def associate_labels(target_sft, min_label=1, max_label=20):
6160
"""
@@ -470,6 +469,7 @@ def subdivide_bundles(sft, sft_centroid, binary_mask, nb_pts,
470469
labels = closest_match_to_centroid(indices,
471470
sft_centroid[0].streamlines._data,
472471
nb_pts=nb_pts)
472+
473473
logging.debug('Computed labels using the euclidian method '
474474
f'in {round(time.time() - timer, 3)} seconds')
475475

scilpy/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Format expected by setup.py and doc/source/conf.py: string of form "X.Y.Z"
88
_version_major = 2
99
_version_minor = 1
10-
_version_micro = 1
10+
_version_micro = 2
1111
_version_extra = ''
1212

1313
# Construct full version string from these.

0 commit comments

Comments
 (0)