Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to fix issue #361: matrix sizing in tracking.utils.connectivity_matrix #362

Merged
merged 3 commits into from May 6, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dipy/tracking/_utils.py
Expand Up @@ -210,7 +210,7 @@ def connectivity_matrix(streamlines, label_volume, voxel_size=None,
endlabels = label_volume[i, j, k]
if symmetric:
endlabels.sort(0)
mx = endlabels.max() + 1
mx = label_volume.max() + 1
matrix = ndbincount(endlabels, shape=(mx, mx))
if symmetric:
matrix = np.maximum(matrix, matrix.T)
Expand Down
16 changes: 16 additions & 0 deletions dipy/tracking/tests/test_utils.py
Expand Up @@ -410,3 +410,19 @@ def test_seeds_from_mask():
in_444 = ((seeds > 3.5) & (seeds < 4.5)).all(1)
assert_equal(in_444.sum(), 3 * 4 * 5)


def test_connectivity_matrix_shape():

# Labels: z-planes have labels 0,1,2
labels = np.zeros((3,3,3))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass the dtype to zeros right here so you don't have to cast to int later, ie labels = np.zeros((3, 3, 3), dtype=int).

labels[:,:,1] = 1
labels[:,:,2] = 2
# Streamline set, only moves between first two z-planes.
streamlines = [np.array([[0., 0., 0.],
[0., 0., 0.5],
[0., 0., 1.]]),
np.array([[0., 1., 1.],
[0., 1., 0.5],
[0., 1., 0.]])]
matrix = connectivity_matrix(streamlines,labels.astype('int'),affine=np.eye(4))
assert_equal(matrix.shape,(3,3))