def voxel2streamline(streamline, affine, unique_idx=None): """ Maps voxels to streamlines and streamlines to voxels, for setting up the LiFE equations matrix Parameters ---------- streamline : list A collection of streamlines, each n by 3, with n being the number of nodes in the fiber. affine : array_like (4, 4) The mapping from voxel coordinates to streamline points. The voxel_to_rasmm matrix, typically from a NIFTI file. unique_idx : array (optional). The unique indices in the streamlines Returns ------- v2f, v2fn : tuple of dicts The first dict in the tuple answers the question: Given a voxel (from the unique indices in this model), which fibers pass through it? The second answers the question: Given a streamline, for each voxel that this streamline passes through, which nodes of that streamline are in that voxel? """ transformed_streamline = transform_streamlines(streamline, affine) if unique_idx is None: all_coords = np.concatenate(transformed_streamline) unique_idx = unique_rows(np.round(all_coords)) return _voxel2streamline(transformed_streamline, unique_idx.astype(np.intp))
def voxel2streamline(streamline, transformed=False, affine=None, unique_idx=None): """ Maps voxels to streamlines and streamlines to voxels, for setting up the LiFE equations matrix Parameters ---------- streamline : list A collection of streamlines, each n by 3, with n being the number of nodes in the fiber. affine : 4 by 4 array (optional) Defines the spatial transformation from streamline to data. Default: np.eye(4) transformed : bool (optional) Whether the streamlines have been already transformed (in which case they don't need to be transformed in here). unique_idx : array (optional). The unique indices in the streamlines Returns ------- v2f, v2fn : tuple of dicts The first dict in the tuple answers the question: Given a voxel (from the unique indices in this model), which fibers pass through it? The second answers the question: Given a streamline, for each voxel that this streamline passes through, which nodes of that streamline are in that voxel? """ if transformed: transformed_streamline = streamline else: if affine is None: affine = np.eye(4) transformed_streamline = transform_streamlines(streamline, affine) if unique_idx is None: all_coords = np.concatenate(transformed_streamline) unique_idx = unique_rows(all_coords.astype(int)) else: unique_idx = unique_idx return _voxel2streamline(transformed_streamline, unique_idx)
def voxel2streamline(streamline, transformed=False, affine=None, unique_idx=None): """ Maps voxels to streamlines and streamlines to voxels, for setting up the LiFE equations matrix Parameters ---------- streamline : list A collection of streamlines, each n by 3, with n being the number of nodes in the fiber. affine : 4 by 4 array (optional) Defines the spatial transformation from streamline to data. Default: np.eye(4) transformed : bool (optional) Whether the streamlines have been already transformed (in which case they don't need to be transformed in here). unique_idx : array (optional). The unique indices in the streamlines Returns ------- v2f, v2fn : tuple of arrays The first array in the tuple answers the question: Given a voxel (from the unique indices in this model), which fibers pass through it? Shape: (n_voxels, n_fibers). The second answers the question: Given a voxel, for each fiber, which nodes are in that voxel? Shape: (n_voxels, max(n_nodes per fiber)). """ if transformed: transformed_streamline = streamline else: if affine is None: affine = np.eye(4) transformed_streamline = transform_streamlines(streamline, affine) if unique_idx is None: all_coords = np.concatenate(transformed_streamline) unique_idx = unique_rows(all_coords.astype(int)) else: unique_idx = unique_idx return _voxel2streamline(transformed_streamline, unique_idx)