It takes the affine matrix from flirt (FSLdot) and the voxel size of the input and output images and it returns the adjusted affine matrix for trackvis.
Counts the streamlines that start and end at each label pair
symmetric means we don’t distiguish between start and end
Counts the number of unique streamlines that pass though each voxel
Counts the number of points in each streamline that lie inside each voxel.
Parameters : | streamlines : iterable
vol_dims : 3 ints
voxel_size : 3 floats
|
---|---|
Returns : | image_volume : ndarray, shape=vol_dims
|
Raises : | IndexError :
|
Notes
A streamline can pass though a voxel even if one of the points of the streamline does not lie in the voxel. For example a step from [0,0,0] to [0,0,2] passes though [0,0,1]. Consider subsegmenting the streamlines when the edges of the voxels are smaller than the steps of the streamlines.
Calculates the lenth of each streamline in a sequence of streamlines
Sums the lenths of each segment in a streamline to get the length of the streamline. Returns a generator.
Example: >>> streamlines = [np.array([[0., 0., 0.], ... [0., 0., 1.], ... [3., 4., 1.]]), ... np.array([[0., 0., 0.]])] >>> list(length(streamlines)) [6.0, 0.0]
Merges two sets of streamlines seeded at the same points
Because the first point of each streamline pair should be the same, only one is kept
Parameters : | backward : iterable
forward : iterable
|
---|---|
Returns : | streamlines : generator
|
Examples
>>> A = [array([[0,0,0],[1,1,1],[2,2,2]])]
>>> B = [array([[0,0,0],[-1,-1,-1],[-2,-2,-2]])]
>>> list(merge_streamlines(A,B))
[array([[ 2, 2, 2],
[ 1, 1, 1],
[ 0, 0, 0],
[-1, -1, -1],
[-2, -2, -2]])]
>>> list(merge_streamlines(B,A))
[array([[-2, -2, -2],
[-1, -1, -1],
[ 0, 0, 0],
[ 1, 1, 1],
[ 2, 2, 2]])]
Applies a linear transformation, given by affine, to streamlines
Parameters : | streamlines : sequence
affine : array (4, 4)
|
---|---|
Returns : | streamlines : generator
|
Like bincount, but for nd-indicies
Parameters : | x : array_like (N, M)
weights : array_like (M,), optional
shape : optional
|
---|
Reduces an array of labels to the integers from 0 to n with smallest possible n
Examples
>>> labels = np.array([[1, 3, 9],
... [1, 3, 8],
... [1, 3, 7]])
>>> new_labels, lookup = reduce_labels(labels)
>>> lookup
array([1, 3, 7, 8, 9])
>>> new_labels
array([[0, 1, 4],
[0, 1, 3],
[0, 1, 2]])
>>> (lookup[new_labels] == labels).all()
True
Calculates a linear tranformation equivelent to chaning voxel order
Calculates a linear tranformation A such that [a, b, c, 1] = A[x, y, z, 1]. where [x, y, z] is a point in the coordinate system defined by input_ornt and [a, b, c] is the same point in the coordinate system defined by output_ornt.
Parameters : | input_ornt : array (n, 2)
output_ornt : array (n, 2)
shape : tuple of int
voxel_size : int
|
---|---|
Returns : | A : array (n+1, n+1)
|
See also
nibabel.orientation, dipy.io.bvectxt.orientation_to_string, dipy.io.bvectxt.orientation_from_string
Takes a binary mask and returns seeds in voxels != 0
places evanly spaced points in nonzero voxels of mask, spaces the points based on density. For example if density is [1, 2, 3], there will be 6 points in each voxel, at x=.5, y=[.25, .75] and z=[.166, .5, .833]. density=a is the same as density = [a, a, a]
Examples
>>> mask = zeros((3,3,3), 'bool')
>>> mask[0,0,0] = 1
>>> seeds_from_mask(mask, [1,1,1], [1,1,1])
array([[ 0.5, 0.5, 0.5]])
>>> seeds_from_mask(mask, [1,2,3], [1,1,1])
array([[ 0.5 , 0.25 , 0.16666667],
[ 0.5 , 0.25 , 0.5 ],
[ 0.5 , 0.25 , 0.83333333],
[ 0.5 , 0.75 , 0.16666667],
[ 0.5 , 0.75 , 0.5 ],
[ 0.5 , 0.75 , 0.83333333]])
>>> mask[0,1,2] = 1
>>> seeds_from_mask(mask, [1,1,2], [1.1,1.1,2.5])
array([[ 0.55 , 0.55 , 0.625],
[ 0.55 , 0.55 , 1.875],
[ 0.55 , 1.65 , 5.625],
[ 0.55 , 1.65 , 6.875]])
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.
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
Splits the segments of the streamlines into small segments
Replaces each segment of each of the streamlines with the smallest possible number ofequally sized smaller segments such that no segmentment is longer than max_segment_length. Among other things, this can useful for getting streamline counts on a grid that is smaller than the length of the streamline segments.
Parameters : | streamlines : sequence of ndarrays
max_segment_length : float
|
---|---|
Returns : | output_streamlines : generator
|
Notes
Segments of 0 length are removed. If unchanged
Examples
>>> streamlines = [array([[0,0,0],[2,0,0],[5,0,0]])]
>>> list(subsegment(streamlines, 3.))
[array([[ 0., 0., 0.],
[ 2., 0., 0.],
[ 5., 0., 0.]])]
>>> list(subsegment(streamlines, 1))
[array([[ 0., 0., 0.],
[ 1., 0., 0.],
[ 2., 0., 0.],
[ 3., 0., 0.],
[ 4., 0., 0.],
[ 5., 0., 0.]])]
>>> list(subsegment(streamlines, 1.6))
[array([[ 0. , 0. , 0. ],
[ 1. , 0. , 0. ],
[ 2. , 0. , 0. ],
[ 3.5, 0. , 0. ],
[ 5. , 0. , 0. ]])]
Retain tracks that pass though target_mask
This function loops over the streamlines and returns streamlines that pass though target_mask.
Parameters : | streamlines : iterable
target_mask : array-like
voxel_size :
|
---|---|
Returns : | streamlines : generator
|
Raises : | IndexError :
|
See also