This module contains the parts of dipy.tracking.utils that need to be implemented in cython.
Creates a mapping from voxel indices to streamlines.
Returns a dictionary where each key is a 3d voxel index and the associated value is a list of the streamlines that pass through that voxel.
Parameters : | streamlines : sequence
voxel_size : array_like (3,), optional
affine : array_like (4, 4), optional
mapping_as_streamlines : bool, optional, False by default
|
---|---|
Returns : | mapping : defaultdict(list)
|
Examples
>>> streamlines = [np.array([[0., 0., 0.],
... [1., 1., 1.],
... [2., 3., 4.]]),
... np.array([[0., 0., 0.],
... [1., 2., 3.]])]
>>> mapping = streamline_mapping(streamlines, (1, 1, 1))
>>> mapping[0, 0, 0]
[0, 1]
>>> mapping[1, 1, 1]
[0]
>>> mapping[1, 2, 3]
[1]
>>> mapping.get((3, 2, 1), 'no streamlines')
'no streamlines'
>>> mapping = streamline_mapping(streamlines, (1, 1, 1),
... mapping_as_streamlines=True)
>>> mapping[1, 2, 3][0] is streamlines[1]
True
Counts of points in tracks that pass through voxels in volume
We find whether a point passed through a track by rounding the mm point values to voxels. For a track that passes through a voxel more than once, we only record counts and elements for the first point in the line that enters the voxel.
Parameters : | tracks : sequence
vol_dims : sequence length 3
vox_sizes : optional, sequence length 3
return_elements : {True, False}, optional
|
---|---|
Returns : | tcs : ndarray shape vol_dim
tes : ndarray dtype np.object, shape vol_dim
|
Examples
Imagine you have a volume (voxel) space of dimension (10,20,30). Imagine you had voxel coordinate tracks in vs. To just fill an array with the counts of how many tracks pass through each voxel:
>>> vox_track0 = np.array([[0,0,0],[1.1,2.2,3.3],[2.2,4.4,6.6]])
>>> vox_track1 = np.array([[0,0,0],[0,0,1],[0,0,2]])
>>> vs = (vox_track0, vox_track1)
>>> vox_dim = (10, 20, 30) # original voxel array size
>>> tcs=track_counts(vs, vox_dim, (1,1,1), False)
>>> tcs.shape
(10, 20, 30)
>>> tcs[0,0,0:4]
array([2, 1, 1, 0])
>>> tcs[1,2,3], tcs[2,4,7]
(1, 1)
You can also use the routine to count into larger-than-voxel boxes. To do this, increase the voxel size and decrease the vox_dim accordingly:
>>> tcs=track_counts(vs, (10/2., 20/2., 30/2.), (2,2,2), False)
>>> tcs.shape
(5, 10, 15)
>>> tcs[1,1,2], tcs[1,2,3]
(1, 1)